Skip to content
On this page

UDF

FunctionDescriptionExample
json_to_mapParse a JSON string into a Map using Standard JSON(https://json.org/).

Args:
json_str (String): The JSON string to parse.

Returns:
Map<String, String>: A map containing the parsing results, where both keys and values are of type string. Returns NULL if parsing fails.
> select json_to_map('{"p":"ordinals"}')["p"];
ordinals
json5_to_mapParse a JSON string into a Map using JSON5(https://json5.org/).

Args:
json_str (String): The JSON string to parse.

Returns:
Map<String, String>: A map containing the parsing results, where both keys and values are of type string. Returns NULL if parsing fails.
> select json5_to_map('{"p":"ordinals",}')["p"];
ordinals
decode_rune(hex)Decode the RUNE(https://rodarmor.com/blog/runes/) protocol message.

Args:
hex(string): The hexadecimal string containing the RUNE protocol message.

Returns:
StructType: A structured data type containing the decoding results, including two fields:
- first_push_numbers (Array<Decimal(38, 0)>): Integer sequence decoded from the first data push in the protocol message.
- assignment_tuples (Array<Array<Decimal(38,0)>>): These first_push_numbers are interpreted as a sequence of (ID, OUTPUT, AMOUNT) tuples.
- second_push_numbers (Array<Decimal(38, 0)>): Integer sequence decoded from the second data push in the protocol message.
- symbol (String): SYMBOL field decoded from the second data push in the protocol message,a human-readable symbol encoded in base 26.
- decimals (Decimal(38, 0)): DECIMALS field decoded from the second data push in the protocol message, the number of digits after the decimal point to be used when displaying the issued rune.
> select decode_rune("6a01520b0001ff00752b7d00000000020112");

{
"first_push_numbers": [
0,
1,
2.1E+9
],
"second_push_numbers": [
1,
18
],
"assignment_tuples": [
[
0,
1,
2.1E+9
]
],
"symbol": "A",
"decimals": 18
}
regexp_extract_all(str, pattern)Extracts all subsequences that match a specified regular expression from a given input string.
You can test the regular expression using https://regexper.com/.
Note: Similarly to the regexp_extract function, if a regexp has a backslash (''), then need to specify '\'

Args:
input_str (String): The input string.
pattern (String): The regular expression pattern.

Returns:
Array<Arrray<String>>: A two-dimensional list containing information about all matches.
Each match is a sublist, where the first element is the entire matching string, followed by the matched strings of each capturing group.
Returns None if no matches are found.
> select regexp_extract_all('alice:123, bob:456', '(\\w+):(\\d+)');

[
[
"alice:123",
"alice",
"123"
],
[
"bob:456",
"bob",
"456"
]
]
decode_bitcoin_script(hex_str)Parse the hexadecimal data of a Bitcoin script into individual operations.

Args:
hex_str (string): The hexadecimal data representing the script.

Returns:
array<struct<op:string, data:string>>: A list of structs containing opcode names and corresponding data for OP_PUSHDATA operations.
> select decode_bitcoin_script("6a01520b0001ffa0860100000000000aff524853030000000012") as operations;

[
{
"op": "RETURN",
"data": null
},
{
"op": "PUSHDATA(1)",
"data": "52"
},
{
"op": "PUSHDATA(11)",
"data": "0001ffa086010000000000"
},
{
"op": "PUSHDATA(10)",
"data": "ff524853030000000012"
}
]
to_bb26(decimal_number)Converts a positive decimal number (> 0) to a bijective base-26 string.
Here’s an example of decimal (base-10) numbers compared to their corresponding BB26(bijective base-26) string:

Decimal: | 1 | 2 | 3 | ... | 24 | 25 | 26 | 27 | 28 | 29 | ...
BB26: | A | B | C | ... | X | Y | Z | AA | AB | AC | ...

bijective base-26: https://en.wikipedia.org/wiki/Bijective_numeration#The_bijective_base-26_system

Args:
decimal_number (int/bigint/decimal): positive decimal number (> 0).

Returns:
string: bijective base-26 string.
> select to_bb26(1);
A

> select to_bb26(27);
AA

> select to_bb26(0);
NULL

> select to_bb26(-1);
NULL
from_bb26(str)Converts a bijective base-26 string to a decimal number.
Here’s an example of decimal (base-10) numbers compared to their corresponding BB26(bijective base-26) string:

BB26: | A | B | C | ... | X | Y | Z | AA | AB | AC | ...
Decimal: | 1 | 2 | 3 | ... | 24 | 25 | 26 | 27 | 28 | 29 | ...

bijective base-26: https://en.wikipedia.org/wiki/Bijective_numeration#The_bijective_base-26_system

Args:
str (string): bijective base-26 string, must consist of uppercase letters A-Z.

Returns:
decimal(38,0): decimal number.
> select from_bb26("A");
1

> select from_bb26("AA");
27

> select from_bb26("A1");
NULL

> select from_bb26("a");
NULL
decode_bitcoin_varints(hex_str)Parse the hexadecimal data of a pushdata operation containing a group of varints.

Args:
hex_str (string): The hexadecimal data of the pushdata operation.

Returns:
array<decimal(38,0)>: A list of decimals.
> select decode_bitcoin_varints("0001ffa086010000000000") as numbers;
[0,1,1E+5]
to_base26(decimal_number)Converts a non-negative decimal number (>= 0) to a base-26 string.
Here’s an example of decimal (base-10) numbers compared to their corresponding base-26 string:

Decimal: | 0 | 1 | 2 | ... | 24 | 25 | 26 | 27 | 28 | ...
Base26: | A | B | C | ... | Y | Z | AA | AB | AC | ...

Args:
decimal_number (int/bigint/decimal): non-negative decimal number (>= 0).

Returns:
string: base-26 string.
> select to_base26(0);
A

> select to_base26(26);
AA

> select to_base26(-1);
NULL
from_base26(str)Converts base-26 string to a decimal number.
Here’s an example of decimal (base-10) numbers compared to their corresponding base-26 string:

Base26: | A | B | C | ... | Y | Z | AA | AB | AC | ...
Decimal: | 0 | 1 | 2 | ... | 24 | 25 | 26 | 27 | 28 | ...

Args:
str (string): base-26 string, must consist of uppercase letters A-Z.

Returns:
decimal(38,0): decimal number.
> select from_base("A");
0

> select from_base("AA");
26

> select from_base("a");
NULL