aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-02-14 21:29:45 +0100
committerPeter Eisentraut <peter@eisentraut.org>2022-02-15 07:58:49 +0100
commit13d129333ee2cc936350cd257af4d0367a6099ac (patch)
treea1422b1caf42a665ba73062d0a41ed11222e1c6f
parent73508475d69e90f98ebd9b7e1a5933a26a49c5e9 (diff)
downloadpostgresql-13d129333ee2cc936350cd257af4d0367a6099ac.tar.gz
postgresql-13d129333ee2cc936350cd257af4d0367a6099ac.zip
Add test case for trailing junk after numeric literals
PostgreSQL currently accepts numeric literals with trailing non-digits, such as 123abc where the abc is treated as the next token. This may be a bit surprising. This commit adds test cases for this; subsequent commits intend to change this behavior. Reviewed-by: John Naylor <john.naylor@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/b239564c-cad0-b23e-c57e-166d883cb97d@enterprisedb.com
-rw-r--r--src/test/regress/expected/numerology.out62
-rw-r--r--src/test/regress/sql/numerology.sql16
2 files changed, 78 insertions, 0 deletions
diff --git a/src/test/regress/expected/numerology.out b/src/test/regress/expected/numerology.out
index 44d6c435ded..2ffc73e8548 100644
--- a/src/test/regress/expected/numerology.out
+++ b/src/test/regress/expected/numerology.out
@@ -3,6 +3,68 @@
-- Test various combinations of numeric types and functions.
--
--
+-- Trailing junk in numeric literals
+--
+SELECT 123abc;
+ abc
+-----
+ 123
+(1 row)
+
+SELECT 0x0o;
+ x0o
+-----
+ 0
+(1 row)
+
+SELECT 1_2_3;
+ _2_3
+------
+ 1
+(1 row)
+
+SELECT 0.a;
+ a
+---
+ 0
+(1 row)
+
+SELECT 0.0a;
+ a
+-----
+ 0.0
+(1 row)
+
+SELECT .0a;
+ a
+-----
+ 0.0
+(1 row)
+
+SELECT 0.0e1a;
+ a
+---
+ 0
+(1 row)
+
+SELECT 0.0e;
+ e
+-----
+ 0.0
+(1 row)
+
+SELECT 0.0e+a;
+ERROR: syntax error at or near "+"
+LINE 1: SELECT 0.0e+a;
+ ^
+PREPARE p1 AS SELECT $1a;
+EXECUTE p1(1);
+ a
+---
+ 1
+(1 row)
+
+--
-- Test implicit type conversions
-- This fails for Postgres v6.1 (and earlier?)
-- so let's try explicit conversions for now - tgl 97/05/07
diff --git a/src/test/regress/sql/numerology.sql b/src/test/regress/sql/numerology.sql
index fddb58f8fdb..fb75f97832d 100644
--- a/src/test/regress/sql/numerology.sql
+++ b/src/test/regress/sql/numerology.sql
@@ -4,6 +4,22 @@
--
--
+-- Trailing junk in numeric literals
+--
+
+SELECT 123abc;
+SELECT 0x0o;
+SELECT 1_2_3;
+SELECT 0.a;
+SELECT 0.0a;
+SELECT .0a;
+SELECT 0.0e1a;
+SELECT 0.0e;
+SELECT 0.0e+a;
+PREPARE p1 AS SELECT $1a;
+EXECUTE p1(1);
+
+--
-- Test implicit type conversions
-- This fails for Postgres v6.1 (and earlier?)
-- so let's try explicit conversions for now - tgl 97/05/07