From 50beee4ae76f39bc7460c4eb18e8c5d66432f3fa Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 23 Dec 2023 10:15:01 +0100 Subject: [PATCH] testing: Directive to expose types (#183) Use the `/* types */` directive to include each value type in the output. This is useful to verify that literals or expressions are being represented as the expected type. --- docs/testing.rst | 13 ++++ tests/arithmetic.sql | 37 ++++++---- tests/bigint.sql | 27 +++++--- tests/boolean.sql | 9 ++- tests/cast.sql | 24 ++++--- tests/coalesce.sql | 6 +- tests/concatenation.sql | 3 +- tests/date-time-value-function.sql | 99 ++++++++++++++++++--------- tests/date.sql | 3 +- tests/double-precision.sql | 54 ++++++++++----- tests/fold.sql | 6 +- tests/integer.sql | 27 +++++--- tests/length.sql | 9 ++- tests/literal.sql | 24 ++++--- tests/math.sql | 57 ++++++++++------ tests/nullif.sql | 6 +- tests/parameters.sql | 15 +++++ tests/pg-functions.sql | 9 ++- tests/position.sql | 6 +- tests/real.sql | 55 ++++++++++----- tests/smallint.sql | 24 ++++--- tests/substring.sql | 54 ++++++++++----- tests/time.sql | 105 +++++++++++++++++++---------- tests/timestamp.sql | 21 ++++-- tests/trim.sql | 24 ++++--- tests/unicode.sql | 9 ++- tests/values.sql | 17 +++-- vsql/sql_test.v | 12 +++- 28 files changed, 515 insertions(+), 240 deletions(-) diff --git a/docs/testing.rst b/docs/testing.rst index 372c301..0cc47db 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -322,6 +322,19 @@ This will be replaced with the correct character before the test runs. This is only a feature of SQL Tests, so will not work in any other context. +Exposing Types +^^^^^^^^^^^^^^ + +Use the ``/* types */`` directive to include each value type in the output. This +is useful to verify that literals or expressions are being represented as the +expected type. + +.. code-block:: sql + + /* types */ + VALUES ROW(2 + 3 * 5, (2 + 3) * 5); + -- COL1: 17 (INTEGER) COL2: 25 (INTEGER) + Debugging Tests --------------- diff --git a/tests/arithmetic.sql b/tests/arithmetic.sql index 02e311e..afd4671 100644 --- a/tests/arithmetic.sql +++ b/tests/arithmetic.sql @@ -1,38 +1,51 @@ +/* types */ VALUES 1 + 2; --- COL1: 3 +-- COL1: 3 (INTEGER) +/* types */ VALUES 1 - 2; --- COL1: -1 +-- COL1: -1 (INTEGER) +/* types */ VALUES 2 * 3; --- COL1: 6 +-- COL1: 6 (INTEGER) +/* types */ VALUES 6 / 2; --- COL1: 3 +-- COL1: 3 (INTEGER) +/* types */ VALUES 1.2 + 2.4; --- COL1: 3.6 +-- COL1: 3.6 (DOUBLE PRECISION) +/* types */ VALUES 1.7 - 0.5; --- COL1: 1.2 +-- COL1: 1.2 (DOUBLE PRECISION) +/* types */ VALUES 2.2 * 3.3; --- COL1: 7.26 +-- COL1: 7.26 (DOUBLE PRECISION) +/* types */ VALUES 6.0 / 2.5; --- COL1: 2.4 +-- COL1: 2.4 (DOUBLE PRECISION) +/* types */ VALUES 0.0 / 2.5; --- COL1: 0 +-- COL1: 0 (DOUBLE PRECISION) +/* types */ VALUES 2.5 / 0.0; -- error 22012: division by zero +/* types */ VALUES -123; --- COL1: -123 +-- COL1: -123 (NUMERIC) +/* types */ VALUES +1.23; --- COL1: 1.23 +-- COL1: 1.23 (NUMERIC) +/* types */ VALUES 1.5 + 2.4 * 7.0; --- COL1: 18.3 +-- COL1: 18.3 (DOUBLE PRECISION) diff --git a/tests/bigint.sql b/tests/bigint.sql index e142a78..4641269 100644 --- a/tests/bigint.sql +++ b/tests/bigint.sql @@ -64,11 +64,13 @@ SELECT CAST(x AS BOOLEAN) FROM foo; -- msg: INSERT 1 -- error 42846: cannot coerce BIGINT to BOOLEAN +/* types */ VALUES CAST(123 AS BIGINT) + 53; --- COL1: 176 +-- COL1: 176 (BIGINT) +/* types */ VALUES 53 + CAST(123 AS BIGINT); --- COL1: 176 +-- COL1: 176 (BIGINT) VALUES CAST(5000000000000000000 AS BIGINT) + 5000000000000000000; -- error 22003: numeric value out of range @@ -76,11 +78,13 @@ VALUES CAST(5000000000000000000 AS BIGINT) + 5000000000000000000; VALUES 5000000000000000000 + CAST(5000000000000000000 AS BIGINT); -- error 22003: numeric value out of range +/* types */ VALUES CAST(123 AS BIGINT) - 53; --- COL1: 70 +-- COL1: 70 (BIGINT) +/* types */ VALUES 53 - CAST(123 AS BIGINT); --- COL1: -70 +-- COL1: -70 (BIGINT) VALUES CAST(-5000000000000000000 AS BIGINT) - 5000000000000000000; -- error 22003: numeric value out of range @@ -88,11 +92,13 @@ VALUES CAST(-5000000000000000000 AS BIGINT) - 5000000000000000000; VALUES -5000000000000000000 - CAST(5000000000000000000 AS BIGINT); -- error 22003: numeric value out of range +/* types */ VALUES CAST(123 AS BIGINT) * 53; --- COL1: 6519 +-- COL1: 6519 (BIGINT) +/* types */ VALUES -53 * CAST(123 AS BIGINT); --- COL1: -6519 +-- COL1: -6519 (BIGINT) VALUES CAST(-5000000000000000000 AS BIGINT) * 200000; -- error 22003: numeric value out of range @@ -100,14 +106,17 @@ VALUES CAST(-5000000000000000000 AS BIGINT) * 200000; VALUES -5000000000000000000 * CAST(5000000000000000000 AS BIGINT); -- error 22003: numeric value out of range +/* types */ VALUES CAST(123 AS BIGINT) / 53; --- COL1: 2 +-- COL1: 2 (BIGINT) +/* types */ VALUES -123 / CAST(53 AS BIGINT); --- COL1: -2 +-- COL1: -2 (BIGINT) +/* types */ VALUES -5000000000000000000 / CAST(3.2 AS BIGINT); --- COL1: -1666666666666666666 +-- COL1: -1666666666666666666 (BIGINT) VALUES CAST(-5000000000000000000 AS BIGINT) / 0; -- error 22012: division by zero diff --git a/tests/boolean.sql b/tests/boolean.sql index 10d847f..9a1c87d 100644 --- a/tests/boolean.sql +++ b/tests/boolean.sql @@ -4,8 +4,9 @@ VALUES TRUE; VALUES FALSE; -- COL1: FALSE +/* types */ VALUES UNKNOWN; --- COL1: UNKNOWN +-- COL1: UNKNOWN (BOOLEAN) CREATE TABLE foo (x BOOLEAN); INSERT INTO foo (x) VALUES (NULL); @@ -47,8 +48,9 @@ VALUES TRUE AND UNKNOWN; VALUES FALSE AND UNKNOWN; -- COL1: FALSE +/* types */ VALUES UNKNOWN AND UNKNOWN; --- COL1: UNKNOWN +-- COL1: UNKNOWN (BOOLEAN) VALUES TRUE OR TRUE; -- COL1: TRUE @@ -155,5 +157,6 @@ VALUES NOT TRUE; VALUES NOT FALSE; -- COL1: TRUE +/* types */ VALUES NOT UNKNOWN; --- COL1: UNKNOWN +-- COL1: UNKNOWN (BOOLEAN) diff --git a/tests/cast.sql b/tests/cast.sql index 82b9e16..0aadfe7 100644 --- a/tests/cast.sql +++ b/tests/cast.sql @@ -1,35 +1,43 @@ +/* types */ VALUES ROW(CAST('abc' AS CHARACTER(3)), CHARACTER_LENGTH(CAST('abc' AS CHARACTER(3)))); --- COL1: abc COL2: 3 +-- COL1: abc (CHARACTER(3)) COL2: 3 (INTEGER) VALUES ROW(CAST('abcde' AS CHARACTER(3)), CHARACTER_LENGTH(CAST('abcde' AS CHARACTER(3)))); -- error 22001: string data right truncation for CHARACTER(3) +/* types */ VALUES ROW(CAST('abc ' AS CHARACTER(3)), CHARACTER_LENGTH(CAST('abc ' AS CHARACTER(3)))); --- COL1: abc COL2: 3 +-- COL1: abc (CHARACTER(3)) COL2: 3 (INTEGER) +/* types */ VALUES ROW(CAST('abc ' AS CHARACTER(3)), CHARACTER_LENGTH(CAST('abc ' AS CHARACTER(3)))); --- COL1: abc COL2: 3 +-- COL1: abc (CHARACTER(3)) COL2: 3 (INTEGER) VALUES ROW(CAST('abc d' AS CHARACTER(3)), CHARACTER_LENGTH(CAST('abc d' AS CHARACTER(3)))); -- error 22001: string data right truncation for CHARACTER(3) +/* types */ VALUES ROW(CAST('abc' AS CHARACTER(4)), CHARACTER_LENGTH(CAST('abc' AS CHARACTER(4)))); --- COL1: abc COL2: 4 +-- COL1: abc (CHARACTER(4)) COL2: 4 (INTEGER) +/* types */ VALUES CAST(123 AS CHARACTER(3)); --- COL1: 123 +-- COL1: 123 (CHARACTER(3)) VALUES CAST(1.23 AS CHARACTER(3)); -- error 22001: string data right truncation for CHARACTER(3) +/* types */ VALUES ROW(CAST('abc' AS VARCHAR(3)), CHARACTER_LENGTH(CAST('abc' AS VARCHAR(3)))); --- COL1: abc COL2: 3 +-- COL1: abc (CHARACTER VARYING(3)) COL2: 3 (INTEGER) +/* types */ VALUES ROW(CAST('abc ' AS VARCHAR(20)), CHARACTER_LENGTH(CAST('abc ' AS VARCHAR(20)))); --- COL1: abc COL2: 4 +-- COL1: abc (CHARACTER VARYING(4)) COL2: 4 (INTEGER) +/* types */ VALUES CAST(123 AS SMALLINT); --- COL1: 123 +-- COL1: 123 (SMALLINT) VALUES CAST(123 AS BOOLEAN); -- error 42846: cannot coerce NUMERIC to BOOLEAN diff --git a/tests/coalesce.sql b/tests/coalesce.sql index d06430f..03f080d 100644 --- a/tests/coalesce.sql +++ b/tests/coalesce.sql @@ -7,11 +7,13 @@ EXPLAIN VALUES COALESCE(1, 2); EXPLAIN VALUES COALESCE(1, 2, 3); -- EXPLAIN: VALUES (COL1 NUMERIC) = ROW(COALESCE(1, 2, 3)) +/* types */ VALUES COALESCE(1); --- COL1: 1 +-- COL1: 1 (NUMERIC) +/* types */ VALUES COALESCE(1, 2); --- COL1: 1 +-- COL1: 1 (NUMERIC) CREATE TABLE foo (f1 BIGINT); INSERT INTO foo (f1) VALUES (NULL); diff --git a/tests/concatenation.sql b/tests/concatenation.sql index 24b4955..d251e71 100644 --- a/tests/concatenation.sql +++ b/tests/concatenation.sql @@ -1,5 +1,6 @@ +/* types */ VALUES 'foo' || 'bar'; --- COL1: foobar +-- COL1: foobar (CHARACTER VARYING(6)) VALUES 123 || 'bar'; -- error 42883: operator does not exist: NUMERIC || CHARACTER diff --git a/tests/date-time-value-function.sql b/tests/date-time-value-function.sql index 9a92208..b4e0f27 100644 --- a/tests/date-time-value-function.sql +++ b/tests/date-time-value-function.sql @@ -1,110 +1,143 @@ +/* types */ VALUES CURRENT_DATE; --- COL1: 2022-07-04 +-- COL1: 2022-07-04 (DATE) +/* types */ VALUES CURRENT_TIME; --- COL1: 14:05:03+0500 +-- COL1: 14:05:03+0500 (TIME(0) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIME(0); --- COL1: 14:05:03+0500 +-- COL1: 14:05:03+0500 (TIME(0) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIME(1); --- COL1: 14:05:03.1+0500 +-- COL1: 14:05:03.1+0500 (TIME(1) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIME(2); --- COL1: 14:05:03.12+0500 +-- COL1: 14:05:03.12+0500 (TIME(2) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIME(3); --- COL1: 14:05:03.120+0500 +-- COL1: 14:05:03.120+0500 (TIME(3) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIME(4); --- COL1: 14:05:03.1200+0500 +-- COL1: 14:05:03.1200+0500 (TIME(4) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIME(5); --- COL1: 14:05:03.12005+0500 +-- COL1: 14:05:03.12005+0500 (TIME(5) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIME(6); --- COL1: 14:05:03.120056+0500 +-- COL1: 14:05:03.120056+0500 (TIME(6) WITH TIME ZONE) VALUES CURRENT_TIME(7); -- error 42601: syntax error: CURRENT_TIME(7): cannot have precision greater than 6 +/* types */ VALUES CURRENT_TIMESTAMP; --- COL1: 2022-07-04T14:05:03.120056+0500 +-- COL1: 2022-07-04T14:05:03.120056+0500 (TIMESTAMP(6) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIMESTAMP(0); --- COL1: 2022-07-04T14:05:03+0500 +-- COL1: 2022-07-04T14:05:03+0500 (TIMESTAMP(0) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIMESTAMP(1); --- COL1: 2022-07-04T14:05:03.1+0500 +-- COL1: 2022-07-04T14:05:03.1+0500 (TIMESTAMP(1) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIMESTAMP(2); --- COL1: 2022-07-04T14:05:03.12+0500 +-- COL1: 2022-07-04T14:05:03.12+0500 (TIMESTAMP(2) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIMESTAMP(3); --- COL1: 2022-07-04T14:05:03.120+0500 +-- COL1: 2022-07-04T14:05:03.120+0500 (TIMESTAMP(3) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIMESTAMP(4); --- COL1: 2022-07-04T14:05:03.1200+0500 +-- COL1: 2022-07-04T14:05:03.1200+0500 (TIMESTAMP(4) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIMESTAMP(5); --- COL1: 2022-07-04T14:05:03.12005+0500 +-- COL1: 2022-07-04T14:05:03.12005+0500 (TIMESTAMP(5) WITH TIME ZONE) +/* types */ VALUES CURRENT_TIMESTAMP(6); --- COL1: 2022-07-04T14:05:03.120056+0500 +-- COL1: 2022-07-04T14:05:03.120056+0500 (TIMESTAMP(6) WITH TIME ZONE) VALUES CURRENT_TIMESTAMP(7); -- error 42601: syntax error: CURRENT_TIMESTAMP(7): cannot have precision greater than 6 +/* types */ VALUES LOCALTIME; --- COL1: 14:05:03 +-- COL1: 14:05:03 (TIME(0) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIME(0); --- COL1: 14:05:03 +-- COL1: 14:05:03 (TIME(0) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIME(1); --- COL1: 14:05:03.1 +-- COL1: 14:05:03.1 (TIME(1) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIME(2); --- COL1: 14:05:03.12 +-- COL1: 14:05:03.12 (TIME(2) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIME(3); --- COL1: 14:05:03.120 +-- COL1: 14:05:03.120 (TIME(3) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIME(4); --- COL1: 14:05:03.1200 +-- COL1: 14:05:03.1200 (TIME(4) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIME(5); --- COL1: 14:05:03.12005 +-- COL1: 14:05:03.12005 (TIME(5) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIME(6); --- COL1: 14:05:03.120056 +-- COL1: 14:05:03.120056 (TIME(6) WITHOUT TIME ZONE) VALUES LOCALTIME(7); -- error 42601: syntax error: LOCALTIME(7): cannot have precision greater than 6 +/* types */ VALUES LOCALTIMESTAMP; --- COL1: 2022-07-04T14:05:03.120056 +-- COL1: 2022-07-04T14:05:03.120056 (TIMESTAMP(6) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIMESTAMP(0); --- COL1: 2022-07-04T14:05:03 +-- COL1: 2022-07-04T14:05:03 (TIMESTAMP(0) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIMESTAMP(1); --- COL1: 2022-07-04T14:05:03.1 +-- COL1: 2022-07-04T14:05:03.1 (TIMESTAMP(1) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIMESTAMP(2); --- COL1: 2022-07-04T14:05:03.12 +-- COL1: 2022-07-04T14:05:03.12 (TIMESTAMP(2) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIMESTAMP(3); --- COL1: 2022-07-04T14:05:03.120 +-- COL1: 2022-07-04T14:05:03.120 (TIMESTAMP(3) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIMESTAMP(4); --- COL1: 2022-07-04T14:05:03.1200 +-- COL1: 2022-07-04T14:05:03.1200 (TIMESTAMP(4) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIMESTAMP(5); --- COL1: 2022-07-04T14:05:03.12005 +-- COL1: 2022-07-04T14:05:03.12005 (TIMESTAMP(5) WITHOUT TIME ZONE) +/* types */ VALUES LOCALTIMESTAMP(6); --- COL1: 2022-07-04T14:05:03.120056 +-- COL1: 2022-07-04T14:05:03.120056 (TIMESTAMP(6) WITHOUT TIME ZONE) VALUES LOCALTIMESTAMP(7); -- error 42601: syntax error: LOCALTIMESTAMP(7): cannot have precision greater than 6 diff --git a/tests/date.sql b/tests/date.sql index 58f8c23..ac9abcf 100644 --- a/tests/date.sql +++ b/tests/date.sql @@ -31,8 +31,9 @@ VALUES DATE 'a2022-06-30 21:47:32'; VALUES DATE '2022-06-30 21:47:32a'; -- error 42601: syntax error: DATE '2022-06-30 21:47:32a' is not valid +/* types */ VALUES DATE '2022-06-30'; --- COL1: 2022-06-30 +-- COL1: 2022-06-30 (DATE) VALUES DATE '21:47:32'; -- error 42601: syntax error: DATE '21:47:32' is not valid diff --git a/tests/double-precision.sql b/tests/double-precision.sql index 8a9e314..ec8d1ea 100644 --- a/tests/double-precision.sql +++ b/tests/double-precision.sql @@ -47,62 +47,80 @@ SELECT CAST(x AS DOUBLE PRECISION) FROM foo; -- msg: INSERT 1 -- COL1: 123 +/* types */ VALUES CAST(500000000.3 AS DOUBLE PRECISION) * 2000000000.7; --- COL1: 1e+18 +-- COL1: 1e+18 (DOUBLE PRECISION) +/* types */ VALUES CAST(1.23 AS DOUBLE PRECISION) + 53.7; --- COL1: 54.93 +-- COL1: 54.93 (DOUBLE PRECISION) +/* types */ VALUES 53.7 + CAST(1.23 AS DOUBLE PRECISION); --- COL1: 54.93 +-- COL1: 54.93 (DOUBLE PRECISION) +/* types */ VALUES CAST(500000000 AS DOUBLE PRECISION) + 2000000000.7; --- COL1: 2.500000e+09 +-- COL1: 2.500000e+09 (DOUBLE PRECISION) +/* types */ VALUES 500000000.7 + CAST(2000000000 AS DOUBLE PRECISION); --- COL1: 2.500000e+09 +-- COL1: 2.500000e+09 (DOUBLE PRECISION) +/* types */ VALUES CAST(1.23 AS DOUBLE PRECISION) - 53.7; --- COL1: -52.47 +-- COL1: -52.47 (DOUBLE PRECISION) +/* types */ VALUES 53.7 - CAST(1.23 AS DOUBLE PRECISION); --- COL1: 52.47 +-- COL1: 52.47 (DOUBLE PRECISION) +/* types */ VALUES CAST(-2000000000.1 AS DOUBLE PRECISION) - 500000000.7; --- COL1: -2.500000e+09 +-- COL1: -2.500000e+09 (DOUBLE PRECISION) +/* types */ VALUES -500000000.7 - CAST(2000000000.1 AS DOUBLE PRECISION); --- COL1: -2.500000e+09 +-- COL1: -2.500000e+09 (DOUBLE PRECISION) +/* types */ VALUES CAST(12.3 AS DOUBLE PRECISION) * 53.7; --- COL1: 660.51 +-- COL1: 660.51 (DOUBLE PRECISION) +/* types */ VALUES -53.7 * CAST(12.3 AS DOUBLE PRECISION); --- COL1: -660.51 +-- COL1: -660.51 (DOUBLE PRECISION) +/* types */ VALUES CAST(-300000.1 AS DOUBLE PRECISION) * 200000.7; --- COL1: -6.000023e+10 +-- COL1: -6.000023e+10 (DOUBLE PRECISION) +/* types */ VALUES -300000.7 * CAST(200000.1 AS DOUBLE PRECISION); --- COL1: -6.000017e+10 +-- COL1: -6.000017e+10 (DOUBLE PRECISION) +/* types */ VALUES CAST(1.23 AS DOUBLE PRECISION) / 53.7; --- COL1: 0.022905 +-- COL1: 0.022905 (DOUBLE PRECISION) +/* types */ VALUES -123.7 / CAST(53.1 AS DOUBLE PRECISION); --- COL1: -2.329567 +-- COL1: -2.329567 (DOUBLE PRECISION) +/* types */ VALUES CAST(-300000000.5 AS DOUBLE PRECISION) / 0.02; --- COL1: -1.500000e+10 +-- COL1: -1.500000e+10 (DOUBLE PRECISION) +/* types */ VALUES -90000.7 / CAST(3.2 AS DOUBLE PRECISION); --- COL1: -28125.21875 +-- COL1: -28125.21875 (DOUBLE PRECISION) VALUES CAST(-30000.5 AS DOUBLE PRECISION) / 0; -- error 22012: division by zero +/* types */ VALUES -90000.5 / CAST(0.1 AS DOUBLE PRECISION); --- COL1: -900005 +-- COL1: -900005 (DOUBLE PRECISION) CREATE TABLE foo (x DOUBLE PRECISION); INSERT INTO foo (x) VALUES (123456789123456789123456789); diff --git a/tests/fold.sql b/tests/fold.sql index 14a5b48..4688c95 100644 --- a/tests/fold.sql +++ b/tests/fold.sql @@ -1,8 +1,10 @@ +/* types */ VALUES UPPER('Hello'); --- COL1: HELLO +-- COL1: HELLO (CHARACTER VARYING(5)) +/* types */ VALUES LOWER('Hello'); --- COL1: hello +-- COL1: hello (CHARACTER VARYING(5)) VALUES UPPER(123); -- error 42883: function does not exist: UPPER(DOUBLE PRECISION) diff --git a/tests/integer.sql b/tests/integer.sql index f166b3a..71c9ef4 100644 --- a/tests/integer.sql +++ b/tests/integer.sql @@ -54,11 +54,13 @@ SELECT CAST(x AS DOUBLE PRECISION) FROM foo; -- msg: INSERT 1 -- COL1: 123 +/* types */ VALUES CAST(123 AS INTEGER) + 53; --- COL1: 176 +-- COL1: 176 (INTEGER) +/* types */ VALUES 53 + CAST(123 AS INTEGER); --- COL1: 176 +-- COL1: 176 (INTEGER) VALUES CAST(500000000 AS INTEGER) + 2000000000; -- error 22003: numeric value out of range @@ -66,11 +68,13 @@ VALUES CAST(500000000 AS INTEGER) + 2000000000; VALUES 500000000 + CAST(2000000000 AS INTEGER); -- error 22003: numeric value out of range +/* types */ VALUES CAST(123 AS INTEGER) - 53; --- COL1: 70 +-- COL1: 70 (INTEGER) +/* types */ VALUES 53 - CAST(123 AS INTEGER); --- COL1: -70 +-- COL1: -70 (INTEGER) VALUES CAST(-2000000000 AS INTEGER) - 500000000; -- error 22003: numeric value out of range @@ -78,11 +82,13 @@ VALUES CAST(-2000000000 AS INTEGER) - 500000000; VALUES -500000000 - CAST(2000000000 AS INTEGER); -- error 22003: numeric value out of range +/* types */ VALUES CAST(123 AS INTEGER) * 53; --- COL1: 6519 +-- COL1: 6519 (INTEGER) +/* types */ VALUES -53 * CAST(123 AS INTEGER); --- COL1: -6519 +-- COL1: -6519 (INTEGER) VALUES CAST(-300000 AS INTEGER) * 200000; -- error 22003: numeric value out of range @@ -90,14 +96,17 @@ VALUES CAST(-300000 AS INTEGER) * 200000; VALUES -300000 * CAST(200000 AS INTEGER); -- error 22003: numeric value out of range +/* types */ VALUES CAST(123 AS INTEGER) / 53; --- COL1: 2 +-- COL1: 2 (INTEGER) +/* types */ VALUES -123 / CAST(53 AS INTEGER); --- COL1: -2 +-- COL1: -2 (INTEGER) +/* types */ VALUES -90000 / CAST(3.2 AS INTEGER); --- COL1: -30000 +-- COL1: -30000 (INTEGER) VALUES CAST(-30000 AS INTEGER) / 0; -- error 22012: division by zero diff --git a/tests/length.sql b/tests/length.sql index 9c7e121..de9d36d 100644 --- a/tests/length.sql +++ b/tests/length.sql @@ -1,11 +1,14 @@ +/* types */ VALUES CHAR_LENGTH('hello Hello'); --- COL1: 11 +-- COL1: 11 (INTEGER) +/* types */ VALUES CHARACTER_LENGTH('hello Hello'); --- COL1: 11 +-- COL1: 11 (INTEGER) +/* types */ VALUES OCTET_LENGTH('hello Hello'); --- COL1: 11 +-- COL1: 11 (INTEGER) VALUES CHAR_LENGTH('😊£'); -- COL1: 2 diff --git a/tests/literal.sql b/tests/literal.sql index 6b76902..23c8102 100644 --- a/tests/literal.sql +++ b/tests/literal.sql @@ -1,23 +1,31 @@ +/* types */ VALUES 1; --- COL1: 1 +-- COL1: 1 (NUMERIC) +/* types */ VALUES 1.23; --- COL1: 1.23 +-- COL1: 1.23 (NUMERIC) +/* types */ VALUES 1.; --- COL1: 1 +-- COL1: 1 (NUMERIC) +/* types */ VALUES .23; --- COL1: 0.23 +-- COL1: 0.23 (NUMERIC) +/* types */ VALUES 789; --- COL1: 789 +-- COL1: 789 (NUMERIC) +/* types */ VALUES 'hello'; --- COL1: hello +-- COL1: hello (CHARACTER(5)) +/* types */ VALUES ROW(123, 456); --- COL1: 123 COL2: 456 +-- COL1: 123 (NUMERIC) COL2: 456 (NUMERIC) +/* types */ VALUES ROW(2 + 3 * 5, (2 + 3) * 5); --- COL1: 17 COL2: 25 +-- COL1: 17 (INTEGER) COL2: 25 (INTEGER) diff --git a/tests/math.sql b/tests/math.sql index 5fa73ce..93bfe9f 100644 --- a/tests/math.sql +++ b/tests/math.sql @@ -10,59 +10,78 @@ VALUES ABS(); VALUES ABS(1, 2); -- error 42601: syntax error: near "," +/* types */ VALUES SIN(1.2); --- COL1: 0.932039 +-- COL1: 0.932039 (DOUBLE PRECISION) +/* types */ VALUES COS(1.2); --- COL1: 0.362358 +-- COL1: 0.362358 (DOUBLE PRECISION) +/* types */ VALUES TAN(1.2); --- COL1: 2.572152 +-- COL1: 2.572152 (DOUBLE PRECISION) +/* types */ VALUES SINH(1.2); --- COL1: 1.509461 +-- COL1: 1.509461 (DOUBLE PRECISION) +/* types */ VALUES COSH(1.2); --- COL1: 1.810656 +-- COL1: 1.810656 (DOUBLE PRECISION) +/* types */ VALUES TANH(1.2); --- COL1: 0.833655 +-- COL1: 0.833655 (DOUBLE PRECISION) +/* types */ VALUES ASIN(0.2); --- COL1: 0.201358 +-- COL1: 0.201358 (DOUBLE PRECISION) +/* types */ VALUES ACOS(0.2); --- COL1: 1.369438 +-- COL1: 1.369438 (DOUBLE PRECISION) +/* types */ VALUES ATAN(0.2); --- COL1: 0.197396 +-- COL1: 0.197396 (DOUBLE PRECISION) +/* types */ VALUES MOD(232.0, 3.0); --- COL1: 1 +-- COL1: 1 (DOUBLE PRECISION) +/* types */ VALUES MOD(10.7, 0.8); --- COL1: 0.3 +-- COL1: 0.3 (DOUBLE PRECISION) +/* types */ VALUES LOG10(13.7); --- COL1: 1.136721 +-- COL1: 1.136721 (DOUBLE PRECISION) +/* types */ VALUES LN(13.7); --- COL1: 2.617396 +-- COL1: 2.617396 (DOUBLE PRECISION) +/* types */ VALUES EXP(3.7); --- COL1: 40.447304 +-- COL1: 40.447304 (DOUBLE PRECISION) +/* types */ VALUES POWER(3.7, 2.5); --- COL1: 26.333241 +-- COL1: 26.333241 (DOUBLE PRECISION) +/* types */ VALUES SQRT(3.7); --- COL1: 1.923538 +-- COL1: 1.923538 (DOUBLE PRECISION) +/* types */ VALUES ROW(FLOOR(3.7), FLOOR(3.3), FLOOR(-3.7), FLOOR(-3.3)); --- COL1: 3 COL2: 3 COL3: -4 COL4: -4 +-- COL1: 3 (DOUBLE PRECISION) COL2: 3 (DOUBLE PRECISION) COL3: -4 (DOUBLE PRECISION) COL4: -4 (DOUBLE PRECISION) +/* types */ VALUES ROW(CEIL(3.7), CEIL(3.3), CEIL(-3.7), CEIL(-3.3)); --- COL1: 4 COL2: 4 COL3: -3 COL4: -3 +-- COL1: 4 (DOUBLE PRECISION) COL2: 4 (DOUBLE PRECISION) COL3: -3 (DOUBLE PRECISION) COL4: -3 (DOUBLE PRECISION) +/* types */ VALUES CEILING(3.7); --- COL1: 4 +-- COL1: 4 (DOUBLE PRECISION) diff --git a/tests/nullif.sql b/tests/nullif.sql index abcc11e..6c42597 100644 --- a/tests/nullif.sql +++ b/tests/nullif.sql @@ -1,11 +1,13 @@ EXPLAIN VALUES NULLIF(TRUE, TRUE); -- EXPLAIN: VALUES (COL1 BOOLEAN) = ROW(NULLIF(TRUE, TRUE)) +/* types */ VALUES NULLIF(123, 123); --- COL1: NULL +-- COL1: NULL (NUMERIC) +/* types */ VALUES NULLIF(123, 456); --- COL1: 123 +-- COL1: 123 (NUMERIC) VALUES NULLIF(123, 'hello'); -- error 42804: data type mismatch in NULLIF: expected NUMERIC but got CHARACTER(5) diff --git a/tests/parameters.sql b/tests/parameters.sql index e3e45f6..7a0bedf 100644 --- a/tests/parameters.sql +++ b/tests/parameters.sql @@ -10,10 +10,20 @@ SELECT * FROM t1; -- msg: INSERT 1 -- X: 2 +/* set foo 2 */ +/* types */ +VALUES :foo; +-- COL1: 2 (DOUBLE PRECISION) + /* set foo 'hello' */ INSERT INTO t1 (x) VALUES (:foo); -- error 22003: numeric value out of range +/* set foo 'hello' */ +/* types */ +VALUES :foo; +-- COL1: hello (CHARACTER(5)) + /* set foo 'hello' */ CREATE TABLE t2 (x VARCHAR(10)); INSERT INTO t2 (x) VALUES (:foo); @@ -59,6 +69,11 @@ SELECT * FROM t1; -- msg: UPDATE 1 -- X: NULL +/* set foo NULL INT */ +/* types */ +VALUES :foo; +-- COL1: NULL (INTEGER) + /* set foo NULL INT */ CREATE TABLE t2 (x INT NOT NULL); UPDATE t2 SET x = :foo; diff --git a/tests/pg-functions.sql b/tests/pg-functions.sql index d718fe7..2350fca 100644 --- a/tests/pg-functions.sql +++ b/tests/pg-functions.sql @@ -1,8 +1,11 @@ +/* types */ VALUES version(); --- COL1: PostgreSQL 9.3.10 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit +-- COL1: PostgreSQL 9.3.10 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit (CHARACTER VARYING(101)) +/* types */ VALUES current_setting('server_version_num'); --- COL1: 90310 +-- COL1: 90310 (CHARACTER VARYING(5)) +/* types */ SELECT * FROM (VALUES current_setting('server_version_num')) AS t1 (ver_num); --- VER_NUM: 90310 +-- VER_NUM: 90310 (CHARACTER VARYING(5)) diff --git a/tests/position.sql b/tests/position.sql index 5c6889b..ae199a9 100644 --- a/tests/position.sql +++ b/tests/position.sql @@ -1,5 +1,6 @@ +/* types */ VALUES POSITION('h' IN 'hello Hello'); --- COL1: 1 +-- COL1: 1 (INTEGER) VALUES POSITION('l' IN 'hello Hello'); -- COL1: 3 @@ -10,5 +11,6 @@ VALUES POSITION('H' IN 'hello Hello'); VALUES POSITION('llo' IN 'hello Hello'); -- COL1: 3 +/* types */ VALUES POSITION('z' IN 'hello Hello'); --- COL1: 0 +-- COL1: 0 (INTEGER) diff --git a/tests/real.sql b/tests/real.sql index 919d707..0c2e453 100644 --- a/tests/real.sql +++ b/tests/real.sql @@ -47,62 +47,81 @@ SELECT CAST(x AS DOUBLE PRECISION) FROM foo; -- msg: INSERT 1 -- COL1: 123 +/* types */ VALUES CAST(500000000.3 AS REAL) * CAST(2000000000.7 AS REAL); --- COL1: 1e+18 +-- COL1: 1e+18 (REAL) +/* types */ VALUES CAST(1.23 AS REAL) + CAST(53.7 AS REAL); --- COL1: 54.93 +-- COL1: 54.93 (REAL) +/* types */ VALUES CAST(53.7 AS REAL) + CAST(1.23 AS REAL); --- COL1: 54.93 +-- COL1: 54.93 (REAL) +/* types */ VALUES CAST(500000000 AS REAL) + CAST(2000000000.7 AS REAL); --- COL1: 2.500000e+09 +-- COL1: 2.500000e+09 (REAL) +/* types */ VALUES CAST(500000000.7 AS REAL) + CAST(2000000000 AS REAL); --- COL1: 2.500000e+09 +-- COL1: 2.500000e+09 (REAL) +/* types */ VALUES CAST(1.23 AS REAL) - CAST(53.7 AS REAL); --- COL1: -52.470001 +-- COL1: -52.470001 (REAL) +/* types */ VALUES CAST(53.7 AS REAL) - CAST(1.23 AS REAL); --- COL1: 52.470001 +-- COL1: 52.470001 (REAL) +/* types */ VALUES CAST(-2000000000.1 AS REAL) - CAST(500000000.7 AS REAL); --- COL1: -2.500000e+09 +-- COL1: -2.500000e+09 (REAL) +/* types */ VALUES CAST(-500000000.7 AS REAL) - CAST(2000000000.1 AS REAL); --- COL1: -2.500000e+09 +-- COL1: -2.500000e+09 (REAL) +/* types */ VALUES CAST(12.3 AS REAL) * CAST(53.7 AS REAL); --- COL1: 660.51001 +-- COL1: 660.51001 (REAL) +/* types */ VALUES CAST(-53.7 AS REAL) * CAST(12.3 AS REAL); --- COL1: -660.51001 +-- COL1: -660.51001 (REAL) +/* types */ VALUES CAST(-300000.1 AS REAL) * CAST(200000.7 AS REAL); --- COL1: -6.000023e+10 +-- COL1: -6.000023e+10 (REAL) +/* types */ VALUES CAST(-300000.7 AS REAL) * CAST(200000.1 AS REAL); --- COL1: -0.6000017e+11 +-- COL1: -0.6000017e+11 (REAL) +/* types */ VALUES CAST(1.23 AS REAL) / CAST(53.7 AS REAL); --- COL1: 0.022905 +-- COL1: 0.022905 (REAL) +/* types */ VALUES CAST(-123.7 AS REAL) / CAST(53.1 AS REAL); --- COL1: -2.329567 +-- COL1: -2.329567 (REAL) +/* types */ VALUES CAST(-300000000.5 AS REAL) / CAST(0.02 AS REAL); --- COL1: -1.500000e+10 +-- COL1: -1.500000e+10 (REAL) +/* types */ VALUES CAST(-90000.7 AS REAL) / CAST(3.2 AS REAL); --- COL1: -28125.21875 +-- COL1: -28125.21875 (REAL) +/* types */ VALUES CAST(-30000.5 AS REAL) / CAST(0 AS REAL); -- error 22012: division by zero +/* types */ VALUES CAST(-90000.5 AS REAL) / CAST(0.1 AS REAL); --- COL1: -900005 +-- COL1: -900005 (REAL) CREATE TABLE foo (x REAL); INSERT INTO foo (x) VALUES (123456789123456789123456789); diff --git a/tests/smallint.sql b/tests/smallint.sql index 9eb8a26..1bd314a 100644 --- a/tests/smallint.sql +++ b/tests/smallint.sql @@ -47,11 +47,13 @@ SELECT CAST(x AS DOUBLE PRECISION) FROM foo; -- msg: INSERT 1 -- COL1: 123 +/* types */ VALUES CAST(123 AS SMALLINT) + CAST(53 AS SMALLINT); --- COL1: 176 +-- COL1: 176 (SMALLINT) +/* types */ VALUES CAST(53 AS SMALLINT) + CAST(123 AS SMALLINT); --- COL1: 176 +-- COL1: 176 (SMALLINT) VALUES CAST(30000 AS SMALLINT) + CAST(20000 AS SMALLINT); -- error 22003: numeric value out of range @@ -59,11 +61,13 @@ VALUES CAST(30000 AS SMALLINT) + CAST(20000 AS SMALLINT); VALUES CAST(30000 AS SMALLINT) + CAST(20000 AS SMALLINT); -- error 22003: numeric value out of range +/* types */ VALUES CAST(123 AS SMALLINT) - CAST(53 AS SMALLINT); --- COL1: 70 +-- COL1: 70 (SMALLINT) +/* types */ VALUES CAST(53 AS SMALLINT) - CAST(123 AS SMALLINT); --- COL1: -70 +-- COL1: -70 (SMALLINT) VALUES CAST(-30000 AS SMALLINT) - CAST(20000 AS SMALLINT); -- error 22003: numeric value out of range @@ -71,11 +75,13 @@ VALUES CAST(-30000 AS SMALLINT) - CAST(20000 AS SMALLINT); VALUES CAST(-30000 AS SMALLINT) - CAST(20000 AS SMALLINT); -- error 22003: numeric value out of range +/* types */ VALUES CAST(123 AS SMALLINT) * CAST(53 AS SMALLINT); --- COL1: 6519 +-- COL1: 6519 (SMALLINT) +/* types */ VALUES CAST(-53 AS SMALLINT) * CAST(123 AS SMALLINT); --- COL1: -6519 +-- COL1: -6519 (SMALLINT) VALUES CAST(-30000 AS SMALLINT) * CAST(20000 AS SMALLINT); -- error 22003: numeric value out of range @@ -83,11 +89,13 @@ VALUES CAST(-30000 AS SMALLINT) * CAST(20000 AS SMALLINT); VALUES CAST(-30000 AS SMALLINT) * CAST(20000 AS SMALLINT); -- error 22003: numeric value out of range +/* types */ VALUES CAST(123 AS SMALLINT) / CAST(53 AS SMALLINT); --- COL1: 2 +-- COL1: 2 (SMALLINT) +/* types */ VALUES CAST(-123 AS SMALLINT) / CAST(53 AS SMALLINT); --- COL1: -2 +-- COL1: -2 (SMALLINT) VALUES CAST(-30000 AS SMALLINT) / CAST(0 AS SMALLINT); -- error 22012: division by zero diff --git a/tests/substring.sql b/tests/substring.sql index d7ce1b2..c075543 100644 --- a/tests/substring.sql +++ b/tests/substring.sql @@ -13,56 +13,74 @@ EXPLAIN VALUES SUBSTRING('hello world' FROM 3 FOR 5 USING CHARACTERS); EXPLAIN VALUES SUBSTRING('hello world' FROM 3 FOR 2 + 3 USING OCTETS); -- EXPLAIN: VALUES (COL1 CHARACTER VARYING) = ROW(SUBSTRING('hello world' FROM 3 FOR 2 + 3 USING OCTETS)) +/* types */ VALUES SUBSTRING('hello' FROM 0); --- COL1: +-- COL1: (CHARACTER VARYING) +/* types */ VALUES SUBSTRING('hello' FROM 2); --- COL1: ello +-- COL1: ello (CHARACTER VARYING(4)) +/* types */ VALUES SUBSTRING('hello' FROM 4); --- COL1: lo +-- COL1: lo (CHARACTER VARYING(2)) +/* types */ VALUES SUBSTRING('hello' FROM 5); --- COL1: o +-- COL1: o (CHARACTER VARYING(1)) +/* types */ VALUES SUBSTRING('hello' FROM 6); --- COL1: +-- COL1: (CHARACTER VARYING) +/* types */ VALUES SUBSTRING('hello' FROM 20); --- COL1: +-- COL1: (CHARACTER VARYING) +/* types */ VALUES SUBSTRING('hello' FROM -1); --- COL1: +-- COL1: (CHARACTER VARYING) +/* types */ VALUES SUBSTRING('hello world' FROM 3 FOR 5); --- COL1: llo w +-- COL1: llo w (CHARACTER VARYING(5)) +/* types */ VALUES SUBSTRING('hello world' FROM 3 USING CHARACTERS); --- COL1: llo world +-- COL1: llo world (CHARACTER VARYING(9)) +/* types */ VALUES SUBSTRING('hello world' FROM 3 FOR 5 USING CHARACTERS); --- COL1: llo w +-- COL1: llo w (CHARACTER VARYING(5)) +/* types */ VALUES SUBSTRING('Жabڣc' FROM 1); --- COL1: Жabڣc +-- COL1: Жabڣc (CHARACTER VARYING(7)) +/* types */ VALUES SUBSTRING('Жabڣc' FROM 2); --- COL1: abڣc +-- COL1: abڣc (CHARACTER VARYING(5)) +/* types */ VALUES SUBSTRING('Жabڣc' FROM 1 FOR 1); --- COL1: Ж +-- COL1: Ж (CHARACTER VARYING(2)) +/* types */ VALUES SUBSTRING('Жabڣc' FROM 1 FOR 2); --- COL1: Жa +-- COL1: Жa (CHARACTER VARYING(3)) +/* types */ VALUES SUBSTRING('Жabڣc' FROM 3 USING OCTETS); --- COL1: abڣc +-- COL1: abڣc (CHARACTER VARYING(5)) +/* types */ VALUES SUBSTRING('Жabڣc' FROM 4 USING OCTETS); --- COL1: bڣc +-- COL1: bڣc (CHARACTER VARYING(4)) +/* types */ VALUES SUBSTRING('Жabڣc' FROM 1 FOR 2 USING OCTETS); --- COL1: Ж +-- COL1: Ж (CHARACTER VARYING(2)) +/* types */ VALUES SUBSTRING('Жabڣc' FROM 3 FOR 2 USING OCTETS); --- COL1: ab +-- COL1: ab (CHARACTER VARYING(2)) diff --git a/tests/time.sql b/tests/time.sql index 691b1ca..ca93bc0 100644 --- a/tests/time.sql +++ b/tests/time.sql @@ -4,8 +4,9 @@ VALUES TIME '2022-06-30 21:47:32'; VALUES TIME '2022-06-30 21:47:32+05:12'; -- error 42601: syntax error: TIME '2022-06-30 21:47:32+05:12' is not valid +/* types */ VALUES TIME '21:47:32'; --- COL1: 21:47:32 +-- COL1: 21:47:32 (TIME(0) WITHOUT TIME ZONE) VALUES TIME 'a21:47:32'; -- error 42601: syntax error: TIME 'a21:47:32' is not valid @@ -13,14 +14,17 @@ VALUES TIME 'a21:47:32'; VALUES TIME '21:47:32T'; -- error 42601: syntax error: TIME '21:47:32T' is not valid +/* types */ VALUES TIME '21:47:32+05:12'; --- COL1: 21:47:32+0512 +-- COL1: 21:47:32+0512 (TIME(0) WITH TIME ZONE) +/* types */ VALUES TIME '21:47:32-11:30'; --- COL1: 21:47:32-1130 +-- COL1: 21:47:32-1130 (TIME(0) WITH TIME ZONE) +/* types */ VALUES TIME '21:47:32.123+05:12'; --- COL1: 21:47:32.123+0512 +-- COL1: 21:47:32.123+0512 (TIME(3) WITH TIME ZONE) VALUES TIME '2022-06-30 21:47:32-11:30'; -- error 42601: syntax error: TIME '2022-06-30 21:47:32-11:30' is not valid @@ -46,8 +50,9 @@ VALUES TIME '2022-06-30 21:47:32a'; VALUES TIME '2022-06-30'; -- error 42601: syntax error: TIME '2022-06-30' is not valid +/* types */ VALUES TIME '21:47:32'; --- COL1: 21:47:32 +-- COL1: 21:47:32 (TIME(0) WITHOUT TIME ZONE) VALUES TIME 'FOO BAR'; -- error 42601: syntax error: TIME 'FOO BAR' is not valid @@ -68,10 +73,14 @@ VALUES TIME '2022-06-30 21:47:32-12:00'; -- error 42601: syntax error: TIME '2022-06-30 21:47:32-12:00' is not valid CREATE TABLE foo (f1 TIME WITHOUT TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32'); -INSERT INTO foo (f1) VALUES (TIME '01:47:32+05:12'); -INSERT INTO foo (f1) VALUES (TIME '21:47:32.123'); -INSERT INTO foo (f1) VALUES (TIME '01:47:32.123456+05:12'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32'); +INSERT INTO foo (f1) +VALUES (TIME '01:47:32+05:12'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32.123'); +INSERT INTO foo (f1) +VALUES (TIME '01:47:32.123456+05:12'); SELECT * FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 @@ -84,10 +93,14 @@ SELECT * FROM foo; -- F1: 01:47:32 CREATE TABLE foo (f1 TIME WITH TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32'); -INSERT INTO foo (f1) VALUES (TIME '01:47:32+05:12'); -INSERT INTO foo (f1) VALUES (TIME '21:47:32.123'); -INSERT INTO foo (f1) VALUES (TIME '01:47:32.123456+05:12'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32'); +INSERT INTO foo (f1) +VALUES (TIME '01:47:32+05:12'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32.123'); +INSERT INTO foo (f1) +VALUES (TIME '01:47:32.123456+05:12'); SELECT * FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 @@ -100,10 +113,14 @@ SELECT * FROM foo; -- F1: 01:47:32+0512 CREATE TABLE foo (f1 TIME (3) WITHOUT TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32'); -INSERT INTO foo (f1) VALUES (TIME '01:47:32+05:12'); -INSERT INTO foo (f1) VALUES (TIME '21:47:32.123'); -INSERT INTO foo (f1) VALUES (TIME '01:47:32.123456+05:12'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32'); +INSERT INTO foo (f1) +VALUES (TIME '01:47:32+05:12'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32.123'); +INSERT INTO foo (f1) +VALUES (TIME '01:47:32.123456+05:12'); SELECT * FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 @@ -116,10 +133,14 @@ SELECT * FROM foo; -- F1: 01:47:32.123 CREATE TABLE foo (f1 TIME (3) WITH TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32'); -INSERT INTO foo (f1) VALUES (TIME '01:47:32+05:12'); -INSERT INTO foo (f1) VALUES (TIME '21:47:32.123'); -INSERT INTO foo (f1) VALUES (TIME '01:47:32.123456+05:12'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32'); +INSERT INTO foo (f1) +VALUES (TIME '01:47:32+05:12'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32.123'); +INSERT INTO foo (f1) +VALUES (TIME '01:47:32.123456+05:12'); SELECT * FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 @@ -132,21 +153,24 @@ SELECT * FROM foo; -- F1: 01:47:32.123+0512 CREATE TABLE foo (f1 TIME WITH TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32+05:00'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32+05:00'); SELECT CAST(f1 AS DATE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 -- error 42846: cannot coerce TIME(0) WITH TIME ZONE to DATE CREATE TABLE foo (f1 TIME WITH TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32+05:00'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32+05:00'); SELECT CAST(f1 AS TIME WITH TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 -- COL1: 21:47:32+0500 CREATE TABLE foo (f1 TIME(3) WITH TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32.123+05:00'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32.123+05:00'); SELECT CAST(f1 AS TIME(2) WITH TIME ZONE) FROM foo; SELECT CAST(f1 AS TIME(4) WITH TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 @@ -155,14 +179,16 @@ SELECT CAST(f1 AS TIME(4) WITH TIME ZONE) FROM foo; -- COL1: 21:47:32.1230+0500 CREATE TABLE foo (f1 TIME WITH TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32+05:00'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32+05:00'); SELECT CAST(f1 AS TIME WITHOUT TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 -- COL1: 21:47:32 CREATE TABLE foo (f1 TIME(3) WITH TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32.123+05:00'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32.123+05:00'); SELECT CAST(f1 AS TIME(2) WITHOUT TIME ZONE) FROM foo; SELECT CAST(f1 AS TIME(4) WITHOUT TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 @@ -171,35 +197,40 @@ SELECT CAST(f1 AS TIME(4) WITHOUT TIME ZONE) FROM foo; -- COL1: 21:47:32.1230 CREATE TABLE foo (f1 TIME WITH TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32+05:00'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32+05:00'); SELECT CAST(f1 AS TIMESTAMP WITH TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 -- error 42846: cannot coerce TIME(0) WITH TIME ZONE to TIMESTAMP(6) WITH TIME ZONE CREATE TABLE foo (f1 TIME WITH TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32+05:00'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32+05:00'); SELECT CAST(f1 AS TIMESTAMP WITHOUT TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 -- error 42846: cannot coerce TIME(0) WITH TIME ZONE to TIMESTAMP(6) WITHOUT TIME ZONE CREATE TABLE foo (f1 TIME WITHOUT TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32'); SELECT CAST(f1 AS DATE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 -- error 42846: cannot coerce TIME(0) WITHOUT TIME ZONE to DATE CREATE TABLE foo (f1 TIME WITHOUT TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32'); SELECT CAST(f1 AS TIME WITH TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 -- COL1: 21:47:32+0500 CREATE TABLE foo (f1 TIME(3) WITHOUT TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32.123'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32.123'); SELECT CAST(f1 AS TIME(2) WITH TIME ZONE) FROM foo; SELECT CAST(f1 AS TIME(4) WITH TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 @@ -208,14 +239,16 @@ SELECT CAST(f1 AS TIME(4) WITH TIME ZONE) FROM foo; -- COL1: 21:47:32.1230+0500 CREATE TABLE foo (f1 TIME WITHOUT TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32'); SELECT CAST(f1 AS TIME WITHOUT TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 -- COL1: 21:47:32 CREATE TABLE foo (f1 TIME(3) WITHOUT TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32.123'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32.123'); SELECT CAST(f1 AS TIME(2) WITHOUT TIME ZONE) FROM foo; SELECT CAST(f1 AS TIME(4) WITHOUT TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 @@ -224,14 +257,16 @@ SELECT CAST(f1 AS TIME(4) WITHOUT TIME ZONE) FROM foo; -- COL1: 21:47:32.1230 CREATE TABLE foo (f1 TIME WITHOUT TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32'); SELECT CAST(f1 AS TIMESTAMP WITH TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 -- error 42846: cannot coerce TIME(0) WITHOUT TIME ZONE to TIMESTAMP(6) WITH TIME ZONE CREATE TABLE foo (f1 TIME WITHOUT TIME ZONE); -INSERT INTO foo (f1) VALUES (TIME '21:47:32'); +INSERT INTO foo (f1) +VALUES (TIME '21:47:32'); SELECT CAST(f1 AS TIMESTAMP WITHOUT TIME ZONE) FROM foo; -- msg: CREATE TABLE 1 -- msg: INSERT 1 diff --git a/tests/timestamp.sql b/tests/timestamp.sql index ec76791..871ce7a 100644 --- a/tests/timestamp.sql +++ b/tests/timestamp.sql @@ -1,8 +1,10 @@ +/* types */ VALUES TIMESTAMP '2022-06-30 21:47:32'; --- COL1: 2022-06-30T21:47:32 +-- COL1: 2022-06-30T21:47:32 (TIMESTAMP(0) WITHOUT TIME ZONE) +/* types */ VALUES TIMESTAMP '2022-06-30 21:47:32+05:12'; --- COL1: 2022-06-30T21:47:32+0512 +-- COL1: 2022-06-30T21:47:32+0512 (TIMESTAMP(0) WITH TIME ZONE) VALUES TIMESTAMP '21:47:32'; -- error 42601: syntax error: TIMESTAMP '21:47:32' is not valid @@ -10,17 +12,21 @@ VALUES TIMESTAMP '21:47:32'; VALUES TIMESTAMP '21:47:32+05:12'; -- error 42601: syntax error: TIMESTAMP '21:47:32+05:12' is not valid +/* types */ VALUES TIMESTAMP '2022-06-30 21:47:32-11:30'; --- COL1: 2022-06-30T21:47:32-1130 +-- COL1: 2022-06-30T21:47:32-1130 (TIMESTAMP(0) WITH TIME ZONE) +/* types */ VALUES TIMESTAMP '2022-06-30 00:00:00'; --- COL1: 2022-06-30T00:00:00 +-- COL1: 2022-06-30T00:00:00 (TIMESTAMP(0) WITHOUT TIME ZONE) +/* types */ VALUES TIMESTAMP '2022-06-30 21:47:32.123'; --- COL1: 2022-06-30T21:47:32.123 +-- COL1: 2022-06-30T21:47:32.123 (TIMESTAMP(3) WITHOUT TIME ZONE) +/* types */ VALUES TIMESTAMP '2022-06-30 21:47:32.456000+05:12'; --- COL1: 2022-06-30T21:47:32.456000+0512 +-- COL1: 2022-06-30T21:47:32.456000+0512 (TIMESTAMP(6) WITH TIME ZONE) VALUES TIMESTAMP '2022-06-30T21:47:32'; -- error 42601: syntax error: TIMESTAMP '2022-06-30T21:47:32' is not valid @@ -40,8 +46,9 @@ VALUES TIMESTAMP '21:47:32'; VALUES TIMESTAMP 'FOO BAR'; -- error 42601: syntax error: TIMESTAMP 'FOO BAR' is not valid +/* types */ VALUES TIMESTAMP '2022-06-30 21:47:75'; --- COL1: 2022-06-30T21:48:15 +-- COL1: 2022-06-30T21:48:15 (TIMESTAMP(0) WITHOUT TIME ZONE) VALUES TIMESTAMP '10000-06-30T21:47:32'; -- error 42601: syntax error: TIMESTAMP '10000-06-30T21:47:32' is not valid diff --git a/tests/trim.sql b/tests/trim.sql index 7048024..8c50ddb 100644 --- a/tests/trim.sql +++ b/tests/trim.sql @@ -19,26 +19,34 @@ EXPLAIN VALUES TRIM('a' FROM 'aaababccaa'); EXPLAIN VALUES TRIM(LEADING 'a' FROM 'aaababccaa'); -- EXPLAIN: VALUES (COL1 CHARACTER VARYING) = ROW(TRIM(LEADING 'a' FROM 'aaababccaa')) +/* types */ VALUES TRIM('aaababccaa'); --- COL1: aaababccaa +-- COL1: aaababccaa (CHARACTER VARYING(10)) +/* types */ VALUES TRIM(FROM 'aaababccaa'); --- COL1: aaababccaa +-- COL1: aaababccaa (CHARACTER VARYING(10)) +/* types */ VALUES TRIM(LEADING FROM 'aaababccaa'); --- COL1: aaababccaa +-- COL1: aaababccaa (CHARACTER VARYING(10)) +/* types */ VALUES TRIM(TRAILING FROM 'aaababccaa'); --- COL1: aaababccaa +-- COL1: aaababccaa (CHARACTER VARYING(10)) +/* types */ VALUES TRIM(BOTH FROM 'aaababccaa'); --- COL1: aaababccaa +-- COL1: aaababccaa (CHARACTER VARYING(10)) +/* types */ VALUES TRIM('a' FROM 'aaababccaa'); --- COL1: babcc +-- COL1: babcc (CHARACTER VARYING(5)) +/* types */ VALUES TRIM(LEADING 'a' FROM 'aaababccaa'); --- COL1: babccaa +-- COL1: babccaa (CHARACTER VARYING(7)) +/* types */ VALUES TRIM(TRAILING 'a' FROM 'aaababccaa'); --- COL1: aaababcc +-- COL1: aaababcc (CHARACTER VARYING(8)) diff --git a/tests/unicode.sql b/tests/unicode.sql index 09bf218..325c09e 100644 --- a/tests/unicode.sql +++ b/tests/unicode.sql @@ -1,8 +1,11 @@ +/* types */ VALUES '✌️'; --- COL1: ✌️ +-- COL1: ✌️ (CHARACTER(6)) +/* types */ VALUES 'ぁ'; --- COL1: ぁ +-- COL1: ぁ (CHARACTER(3)) +/* types */ VALUES 'a character'; --- COL1: a • character +-- COL1: a • character (CHARACTER(15)) diff --git a/tests/values.sql b/tests/values.sql index 092e545..58f2c2e 100644 --- a/tests/values.sql +++ b/tests/values.sql @@ -45,21 +45,26 @@ SELECT * FROM (VALUES 1, 'foo', TRUE) AS t1 (abc, col2, "f"); SELECT * FROM (VALUES ROW(1, 'foo', TRUE)) AS t1 (abc, col2, "f"); -- ABC: 1 COL2: foo f: TRUE +/* types */ VALUES 'cool'; --- COL1: cool +-- COL1: cool (CHARACTER(4)) +/* types */ VALUES 'cool', 12.3; --- COL1: cool --- COL1: 12.3 +-- COL1: cool (CHARACTER(4)) +-- COL1: 12.3 (NUMERIC) +/* types */ VALUES ROW('cool', 12.3); --- COL1: cool COL2: 12.3 +-- COL1: cool (CHARACTER(4)) COL2: 12.3 (NUMERIC) +/* types */ VALUES '12.3'; --- COL1: 12.3 +-- COL1: 12.3 (CHARACTER(4)) +/* types */ VALUES '2022-06-30 21:47:32'; --- COL1: 2022-06-30 21:47:32 +-- COL1: 2022-06-30 21:47:32 (CHARACTER(19)) EXPLAIN VALUES 'hello'; -- EXPLAIN: VALUES (COL1 CHARACTER(5)) = ROW('hello') diff --git a/vsql/sql_test.v b/vsql/sql_test.v index 857eca6..60a089d 100644 --- a/vsql/sql_test.v +++ b/vsql/sql_test.v @@ -11,6 +11,7 @@ struct SQLTest { line_number int stmts []string expected string + show_types bool } fn get_test_filter() (string, int) { @@ -45,13 +46,15 @@ fn get_tests() ![]SQLTest { mut setup_stmt := '' mut in_setup := false mut params := map[string]Value{} + mut show_types := false for line in lines { if line == '' { - tests << SQLTest{setup, params, test_file_path, line_number, stmts, expected.join('\n')} + tests << SQLTest{setup, params, test_file_path, line_number, stmts, expected.join('\n'), show_types} stmts = [] expected = [] in_setup = false params = map[string]Value{} + show_types = false } else if line.starts_with('/*') { contents := line[2..line.len - 2].trim_space() if contents == 'setup' { @@ -60,6 +63,8 @@ fn get_tests() ![]SQLTest { stmts << replace_unicode(contents) } else if contents.starts_with('create_catalog ') { stmts << replace_unicode(contents) + } else if contents.starts_with('types') { + show_types = true } else if contents.starts_with('set ') { parts := contents.split(' ') if parts[2].starts_with("'") { @@ -98,7 +103,7 @@ fn get_tests() ![]SQLTest { } if stmts.len > 0 { - tests << SQLTest{setup, params, test_file_path, line_number, stmts, expected.join('\n')} + tests << SQLTest{setup, params, test_file_path, line_number, stmts, expected.join('\n'), show_types} } } @@ -256,6 +261,9 @@ fn run_single_test(test SQLTest, query_cache &QueryCache, verbose bool, filter_l for col in result.columns { line += '${col.name.sub_entity_name}: ${row.get_string(col.name.sub_entity_name)!} ' + if test.show_types { + line += '(${row.get(col.name.sub_entity_name)!.typ}) ' + } } actual += line.trim_space() + '\n' }