aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorNathan Bossart <nathan@postgresql.org>2023-08-23 07:49:03 -0700
committerNathan Bossart <nathan@postgresql.org>2023-08-23 07:49:03 -0700
commit260a1f18dae8729f99cefe4e1f759193fd6bedd0 (patch)
tree63fa3c210deaf8877d786c03351eadc88d73a734 /doc/src
parentccadf73163ca88bdaa74b8223d4dde05d17f550b (diff)
downloadpostgresql-260a1f18dae8729f99cefe4e1f759193fd6bedd0.tar.gz
postgresql-260a1f18dae8729f99cefe4e1f759193fd6bedd0.zip
Add to_bin() and to_oct().
This commit introduces functions for converting numbers to their equivalent binary and octal representations. Also, the base conversion code for these functions and to_hex() has been moved to a common helper function. Co-authored-by: Eric Radman Reviewed-by: Ian Barwick, Dag Lem, Vignesh C, Tom Lane, Peter Eisentraut, Kirk Wolak, Vik Fearing, John Naylor, Dean Rasheed Discussion: https://postgr.es/m/Y6IyTQQ/TsD5wnsH%40vm3.eradman.com
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/func.sgml59
1 files changed, 58 insertions, 1 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index be2f54c9141..7a0d4b9134d 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -3740,6 +3740,32 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
+ <primary>to_bin</primary>
+ </indexterm>
+ <function>to_bin</function> ( <type>integer</type> )
+ <returnvalue>text</returnvalue>
+ </para>
+ <para role="func_signature">
+ <function>to_bin</function> ( <type>bigint</type> )
+ <returnvalue>text</returnvalue>
+ </para>
+ <para>
+ Converts the number to its equivalent two's complement binary
+ representation.
+ </para>
+ <para>
+ <literal>to_bin(2147483647)</literal>
+ <returnvalue>1111111111111111111111111111111</returnvalue>
+ </para>
+ <para>
+ <literal>to_bin(-1234)</literal>
+ <returnvalue>11111111111111111111101100101110</returnvalue>
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ <indexterm>
<primary>to_hex</primary>
</indexterm>
<function>to_hex</function> ( <type>integer</type> )
@@ -3750,11 +3776,42 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
<returnvalue>text</returnvalue>
</para>
<para>
- Converts the number to its equivalent hexadecimal representation.
+ Converts the number to its equivalent two's complement hexadecimal
+ representation.
</para>
<para>
<literal>to_hex(2147483647)</literal>
<returnvalue>7fffffff</returnvalue>
+ </para>
+ <para>
+ <literal>to_hex(-1234)</literal>
+ <returnvalue>fffffb2e</returnvalue>
+ </para></entry>
+ </row>
+
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ <indexterm>
+ <primary>to_oct</primary>
+ </indexterm>
+ <function>to_oct</function> ( <type>integer</type> )
+ <returnvalue>text</returnvalue>
+ </para>
+ <para role="func_signature">
+ <function>to_oct</function> ( <type>bigint</type> )
+ <returnvalue>text</returnvalue>
+ </para>
+ <para>
+ Converts the number to its equivalent two's complement octal
+ representation.
+ </para>
+ <para>
+ <literal>to_oct(2147483647)</literal>
+ <returnvalue>17777777777</returnvalue>
+ </para>
+ <para>
+ <literal>to_oct(-1234)</literal>
+ <returnvalue>37777775456</returnvalue>
</para></entry>
</row>