summaryrefslogtreecommitdiff
path: root/src/test/regress
diff options
context:
space:
mode:
authorNathan Bossart2023-08-23 14:49:03 +0000
committerNathan Bossart2023-08-23 14:49:03 +0000
commit260a1f18dae8729f99cefe4e1f759193fd6bedd0 (patch)
tree63fa3c210deaf8877d786c03351eadc88d73a734 /src/test/regress
parentccadf73163ca88bdaa74b8223d4dde05d17f550b (diff)
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 'src/test/regress')
-rw-r--r--src/test/regress/expected/strings.out62
-rw-r--r--src/test/regress/sql/strings.sql15
2 files changed, 74 insertions, 3 deletions
diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out
index 62698569e1a..b7500d9c0e7 100644
--- a/src/test/regress/expected/strings.out
+++ b/src/test/regress/expected/strings.out
@@ -2129,8 +2129,68 @@ select split_part('@joeuser@mydatabase@','@',-2) AS "mydatabase";
(1 row)
--
--- test to_hex
+-- test to_bin, to_oct, and to_hex
--
+select to_bin(-1234) AS "11111111111111111111101100101110";
+ 11111111111111111111101100101110
+----------------------------------
+ 11111111111111111111101100101110
+(1 row)
+
+select to_bin(-1234::bigint);
+ to_bin
+------------------------------------------------------------------
+ 1111111111111111111111111111111111111111111111111111101100101110
+(1 row)
+
+select to_bin(256*256*256 - 1) AS "111111111111111111111111";
+ 111111111111111111111111
+--------------------------
+ 111111111111111111111111
+(1 row)
+
+select to_bin(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "11111111111111111111111111111111";
+ 11111111111111111111111111111111
+----------------------------------
+ 11111111111111111111111111111111
+(1 row)
+
+select to_oct(-1234) AS "37777775456";
+ 37777775456
+-------------
+ 37777775456
+(1 row)
+
+select to_oct(-1234::bigint) AS "1777777777777777775456";
+ 1777777777777777775456
+------------------------
+ 1777777777777777775456
+(1 row)
+
+select to_oct(256*256*256 - 1) AS "77777777";
+ 77777777
+----------
+ 77777777
+(1 row)
+
+select to_oct(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "37777777777";
+ 37777777777
+-------------
+ 37777777777
+(1 row)
+
+select to_hex(-1234) AS "fffffb2e";
+ fffffb2e
+----------
+ fffffb2e
+(1 row)
+
+select to_hex(-1234::bigint) AS "fffffffffffffb2e";
+ fffffffffffffb2e
+------------------
+ fffffffffffffb2e
+(1 row)
+
select to_hex(256*256*256 - 1) AS "ffffff";
ffffff
--------
diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql
index ca32f6bba53..39596789929 100644
--- a/src/test/regress/sql/strings.sql
+++ b/src/test/regress/sql/strings.sql
@@ -685,10 +685,21 @@ select split_part('joeuser@mydatabase','@',-3) AS "empty string";
select split_part('@joeuser@mydatabase@','@',-2) AS "mydatabase";
--
--- test to_hex
+-- test to_bin, to_oct, and to_hex
--
-select to_hex(256*256*256 - 1) AS "ffffff";
+select to_bin(-1234) AS "11111111111111111111101100101110";
+select to_bin(-1234::bigint);
+select to_bin(256*256*256 - 1) AS "111111111111111111111111";
+select to_bin(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "11111111111111111111111111111111";
+
+select to_oct(-1234) AS "37777775456";
+select to_oct(-1234::bigint) AS "1777777777777777775456";
+select to_oct(256*256*256 - 1) AS "77777777";
+select to_oct(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "37777777777";
+select to_hex(-1234) AS "fffffb2e";
+select to_hex(-1234::bigint) AS "fffffffffffffb2e";
+select to_hex(256*256*256 - 1) AS "ffffff";
select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";
--