Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document jsonb_pretty, jsonb_object, and regexp_split_to_array #1435

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions docs/sql/functions-operators/sql-function-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,39 @@ number

```

### `jsonb_pretty`

This function takes a `jsonb` value and returns a text representing the formatted, indented JSON value.

```sql title=Syntax
jsonb_pretty ( jsonb JSONB ) → TEXT
```

```sql title=Examples
SELECT jsonb_pretty('[{"f1":1,"f2":null}, 2]');
------RESULT
[
{
"f1": 1,
"f2": null
},
2
]
```

### `jsonb_object`

This function takes an array of text elements and returns a `jsonb` object where adjacent pairs of values are taken as the key and value of an object property.

```sql title=Syntax
jsonb_object ( text_array TEXT[] ) → JSONB
```

```sql title=Examples
jsonb_object('{a, 1, b, def, c, 3.5}' :: text[]) → {"a": "1", "b": "def", "c": "3.5"}
jsonb_object(array['a', null]) → {"a": null}
```

## JSON operators

### `jsonb -> integer`
Expand Down Expand Up @@ -199,17 +232,13 @@ SELECT '{"a": "b"}'::jsonb || '42'::jsonb;

This predicate tests whether an expression can be parsed as JSON, optionally of a specified type. It evaluates the JSON structure and returns a boolean result indicating whether the value matches the specified JSON type.

#### Syntax

```sql
```sql title=Syntax
expression IS [ NOT ] JSON [ VALUE | ARRAY | OBJECT | SCALAR ] → bool
```

If SCALAR, ARRAY, or OBJECT is specified, the test is whether or not the JSON is of that particular type.

#### Example

```sql
```sql title=Example
SELECT js,
js IS JSON "json?",
js IS JSON SCALAR "scalar?",
Expand All @@ -218,8 +247,8 @@ SELECT js,
FROM (VALUES
('123'), ('"abc"'), ('{"a": "b"}'), ('[1,2]'),('abc')) foo(js);
```
```
------RESULT

```markdown title=Result

js | json? | scalar? | object? | array?
------------+-------+---------+---------+---------
Expand Down
16 changes: 16 additions & 0 deletions docs/sql/functions-operators/sql-function-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,22 @@ regexp_replace('RisingWave', '[aeiou]', 'X', 1, 3, 'i') → RisingWXve

---

### `regexp_split_to_array`

This function splits a string into an array of substrings based on a regular expression pattern.

```sql title=Syntax
regexp_split_to_array ( input_string TEXT, pattern TEXT ) → TEXT[]
```

```sql title=Examples
regexp_split_to_array('apple,banana,orange', ',') → {apple,banana,orange}
regexp_split_to_array('apple.banana!orange', '[.!]') → {apple,banana,orange}
regexp_split_to_array('applebananaorange', ',') → {applebananaorange}
```

---

### `repeat`

Repeats *input_string* specific times. Null is returned when *times_int* is zero, negative, or null.
Expand Down
Loading