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
This commit is contained in:
Peter Eisentraut 2022-02-14 21:29:45 +01:00
parent 73508475d6
commit 13d129333e
2 changed files with 78 additions and 0 deletions

View 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?)

View 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?)