You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/sql-reference/functions/encoding-functions.md
+22-19Lines changed: 22 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -968,29 +968,31 @@ Result:
968
968
1 2
969
969
```
970
970
971
-
## Bech32Encode {#bech32encode}
971
+
## bech32Encode {#bech32encode}
972
972
973
973
Encodes a binary data string, along with a human-readable part (HRP), using the [Bech32 or Bech32m](https://en.bitcoin.it/wiki/Bech32) algorithms.
974
974
975
975
**Syntax**
976
976
977
977
```sql
978
-
Bech32Encode(hrp, data[, witver])
978
+
bech32Encode(hrp, data[, witver])
979
979
```
980
980
981
981
**Parameters**
982
982
983
-
-`hrp` — String of 1 - 83 lowercase characters specifying the "human-readable part" of the code. Usually 'bc' or 'tb'. [String](../data-types/string.md),[FixedString](../data-types/fixedstring.md).
984
-
-`data` — String of binary data to encode. [String](../data-types/string.md),[FixedString](../data-types/fixedstring.md).
985
-
-`witver`(optional, default = 1): An [unsigned integer](../../sql-reference/data-types/int-uint.md) specifying the version of the algorithm to run. 0 for Bech32 and 1 or greater for Bech32m.
983
+
-`hrp` — String of 1 - 83 lowercase characters specifying the "human-readable part" of the code. Usually 'bc' or 'tb'. [String](../data-types/string.md) or[FixedString](../data-types/fixedstring.md).
984
+
-`data` — String of binary data to encode. [String](../data-types/string.md) or[FixedString](../data-types/fixedstring.md).
985
+
-`witver`- Witness version. Optional, default = 1. An [UInt*](../data-types/int-uint.md) specifying the version of the algorithm to run. 0 for Bech32 and 1 or greater for Bech32m.
986
986
987
987
:::note
988
-
When using the [FixedString](../data-types/fixedstring.md) data type, if a value does not fully fill the row it is padded with null characters. While the `Bech32Encode` function will handle this automatically for the hrp argument, for the data argument the values must not be padded. For this reason it is not recommended to use the [FixedString](../data-types/fixedstring.md) data type for your data values unless you are certain that they are all the same length and ensure that your [FixedString](../data-types/fixedstring.md) column is set to that length as well.
988
+
When using the [FixedString](../data-types/fixedstring.md) data type, if a value does not fully fill the row it is padded with null characters.
989
+
While the `bech32Encode` function will handle this automatically for the hrp argument, for the data argument the values must not be padded.
990
+
For this reason it is not recommended to use the [FixedString](../data-types/fixedstring.md) data type for your data values unless you are certain that they are all the same length and ensure that your [FixedString](../data-types/fixedstring.md) column is set to that length as well.
989
991
:::
990
992
991
993
**Returned value**
992
994
993
-
- A Bech32 address string, consisting of the human-readable part, a separator character which is always '1', and a data part. The length of the string will never exceed 90 characters. If the algorithm cannot generate a valid address from the input, it will return an empty string
995
+
- A Bech32 address string, consisting of the human-readable part, a separator character which is always '1', and a data part. The length of the string will never exceed 90 characters. If the algorithm cannot generate a valid address from the input, it will return an empty string.
While 'bc' (Mainnet) and 'tb' (Testnet) are the only allowed hrp values for the SegWit address format, Bech32 allows any hrp that satisfies the above requirements.
0 commit comments