Add test case for trailing junk after numeric literals
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 14 Feb 2022 20:29:45 +0000 (21:29 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Tue, 15 Feb 2022 06:58:49 +0000 (07:58 +0100)
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

src/test/regress/expected/numerology.out
src/test/regress/sql/numerology.sql

index 44d6c435dedd3b904345ec10f0a8b627a2846753..2ffc73e854875436a33ac42444398c8c617865d6 100644 (file)
@@ -2,6 +2,68 @@
 -- NUMEROLOGY
 -- 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?)
index fddb58f8fdba24c98f366a0475f9f2a424b660d0..fb75f97832d0e24f5856d53d8589816d29e39731 100644 (file)
@@ -3,6 +3,22 @@
 -- Test various combinations of numeric types and functions.
 --
 
+--
+-- 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?)