|
1 | 1 | SQL Language Extension: UNLIST |
2 | 2 |
|
3 | 3 | Function: |
4 | | - The function parses the input string using the specified delimiter (comma "," is implied by default) and returns the identified substrings as discrete records containing a single field. Additionally, the desired type of the returned field can be specified. If the specified data type conversion is impossible, an error is raised at runtime. |
| 4 | + The function splits the input string by the specified separator (comma "," is used by default) and returns |
| 5 | + the identified substrings as discrete rows with a single column. Additionally, the desired type of the returned |
| 6 | + field can be specified. If the specified data type conversion is not possible, an error is raised at runtime. |
5 | 7 |
|
6 | 8 | Author: |
7 | 9 | Chudaykin Alex <chudaykinalex@gmail.com> |
8 | 10 |
|
9 | 11 | Format |
10 | | - <table value function> ::= |
11 | | - UNLIST ( <input> [, <separator>] [, <data type conversion>] ) [AS] <correlation name> [ ( <derived column name> ) ] |
| 12 | + <unlist> ::= |
| 13 | + UNLIST ( <input> [, <separator>] [<type-conversion>] ) |
| 14 | + [AS] <correlation-name> [ ( <column-name> ) ] |
12 | 15 |
|
13 | | - <input> ::= <value> |
| 16 | + <input> ::= <value> |
14 | 17 |
|
15 | | - <separator> ::= <value> |
| 18 | + <separator> ::= <value> |
16 | 19 |
|
17 | | - <data type conversion> ::= RETURNING <data type> |
| 20 | + <type-conversion> ::= RETURNING <data type> |
18 | 21 |
|
19 | 22 | Syntax Rules: |
20 | 23 |
|
21 | | -1) <input>: any value expression that returns a string/blob of characters (or may be converted to a string), including string literals, table columns, constants, variables, expressions, etc. This parameter is mandatory. |
22 | | -2) <separator>: optional value expression that returns a string which is used as a delimiter (i.e. it separates one value from another inside the input string). It may also be a BLOB TEXT value, limited to 32KB. If an empty string is specified, the output will be just one record containing the input string. If omitted, the comma character is used as a delimiter. |
23 | | -2) <data type>: target data type to convert the output values into. Alternatively, a domain can be specified as the returned type. If omitted, VARCHAR(32) is implied. Feel free to suggest any better alternative default. |
24 | | -3) <correlation name>: alias of the record set returned by the UNLIST function. It is a mandatory parameter (per SQL standard). |
25 | | -4) <derived column name>: optional alias of the column returned by the UNLIST function. If omitted, UNLIST is used as an alias. |
| 24 | +1) <input>: any value expression that returns a string/blob of characters (or may be converted to a string), including |
| 25 | + string literals, table columns, constants, variables, expressions, etc. This parameter is mandatory. |
| 26 | +2) <separator>: optional value expression that returns a string which is used as a delimiter (i.e. it separates one |
| 27 | + value from another inside the input string). It may also be a BLOB TEXT value, limited to 32KB. If an empty string is |
| 28 | + specified, the output will be just one record containing the input string. If omitted, the comma character is used as |
| 29 | + a delimiter. |
| 30 | +2) <data type>: target data type to convert the output values into. Alternatively, a domain can be specified as |
| 31 | + the returned type. If omitted, VARCHAR(32) is implied. Feel free to suggest any better alternative default. |
| 32 | +3) <correlation name>: alias of the record set returned by the UNLIST function. It is a mandatory parameter. |
| 33 | +4) <derived column name>: optional alias of the column returned by the UNLIST function. If omitted, UNLIST is used as |
| 34 | + an alias. |
26 | 35 |
|
27 | 36 | Example: |
28 | 37 | A) |
|
32 | 41 | SELECT * FROM UNLIST('100:200:300:400:500', ':' RETURNING INT) AS U; |
33 | 42 |
|
34 | 43 | C) |
35 | | - SELECT U.* FROM UNLIST(‘text1, text2, text3’) AS U; |
| 44 | + SELECT U.* FROM UNLIST('text1, text2, text3') AS U; |
36 | 45 |
|
37 | 46 | D) |
38 | | - SELECT C0 FROM UNLIST(‘text1, text2, text3’) AS U(C0); |
| 47 | + SELECT C0 FROM UNLIST('text1, text2, text3') AS U(C0); |
39 | 48 |
|
40 | 49 | E) |
41 | | - SELECT U.C0 FROM UNLIST(‘text1, text2, text3’) AS U(C0); |
| 50 | + SELECT U.C0 FROM UNLIST('text1, text2, text3') AS U(C0); |
42 | 51 |
|
43 | 52 | F) |
44 | 53 | SET TERM ^ ; |
|
0 commit comments