From 5812d512708ff7b48f57e6243489cca1f90e64b2 Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Fri, 29 May 1998 13:23:02 +0000 Subject: [PATCH] Add test for UNION. Add additional tests in strings for conversions of the "name" data type. Test SQL92 string functions such as SUBSTRING() and POSITION(). --- src/test/regress/sql/strings.sql | 53 ++++++++++++++++++-- src/test/regress/sql/tests | 1 + src/test/regress/sql/union.sql | 84 ++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 src/test/regress/sql/union.sql diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql index 50453043b1..e2c86449ae 100644 --- a/src/test/regress/sql/strings.sql +++ b/src/test/regress/sql/strings.sql @@ -11,13 +11,60 @@ SELECT 'first line' -- illegal string continuation syntax SELECT 'first line' ' - next line' /* this comment is not allowed here */ -' - third line'; +' - third line' + AS "Illegal comment within continuation"; -- -- test conversions between various string types -- -SELECT text(f1) FROM CHAR_TBL; +SELECT CAST(f1 AS text) AS "text(char)" FROM CHAR_TBL; -SELECT text(f1) FROM VARCHAR_TBL; +SELECT CAST(f1 AS text) AS "text(varchar)" FROM VARCHAR_TBL; + +SELECT CAST(name 'namefield' AS text) AS "text(name)"; + +SELECT CAST(f1 AS char) AS "char(text)" FROM TEXT_TBL; + +SELECT CAST(f1 AS char) AS "char(varchar)" FROM VARCHAR_TBL; + +SELECT CAST(name 'namefield' AS char) AS "char(name)"; + +SELECT CAST(f1 AS varchar) AS "varchar(text)" FROM TEXT_TBL; + +SELECT CAST(f1 AS varchar) AS "varchar(char)" FROM CHAR_TBL; + +SELECT CAST(name 'namefield' AS varchar) AS "varchar(name)"; + +-- +-- test SQL92 string functions +-- + +SELECT TRIM(BOTH FROM ' bunch o blanks ') AS "bunch o blanks"; + +SELECT TRIM(LEADING FROM ' bunch o blanks ') AS "bunch o blanks "; + +SELECT TRIM(TRAILING FROM ' bunch o blanks ') AS " bunch o blanks"; + +SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') AS "some Xs"; + +SELECT SUBSTRING('1234567890' FROM 3) AS "34567890"; + +SELECT SUBSTRING('1234567890' FROM 4 FOR 3) AS "456"; + +SELECT POSITION('4' IN '1234567890') AS "4"; + +SELECT POSITION(5 IN '1234567890') AS "5"; + +-- +-- test implicit type conversion +-- + +SELECT 'unknown' || ' and unknown' AS "Concat unknown types"; + +SELECT text 'text' || ' and unknown' AS "Concat text to unknown type"; + +SELECT text 'text' || char ' and char' AS "Concat text to char"; + +SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar"; diff --git a/src/test/regress/sql/tests b/src/test/regress/sql/tests index a7a061b9be..783cb9691d 100644 --- a/src/test/regress/sql/tests +++ b/src/test/regress/sql/tests @@ -46,6 +46,7 @@ select_into select_distinct select_distinct_on subselect +union aggregates transactions random diff --git a/src/test/regress/sql/union.sql b/src/test/regress/sql/union.sql new file mode 100644 index 0000000000..781de87a86 --- /dev/null +++ b/src/test/regress/sql/union.sql @@ -0,0 +1,84 @@ +-- +-- union.sql +-- + +-- Simple UNION constructs + +SELECT 1 AS two UNION SELECT 2; + +SELECT 1 AS one UNION SELECT 1; + +SELECT 1 AS two UNION ALL SELECT 2; + +SELECT 1 AS two UNION ALL SELECT 1; + +SELECT 1 AS three UNION SELECT 2 UNION SELECT 3; + +SELECT 1 AS two UNION SELECT 2 UNION SELECT 2; + +SELECT 1 AS three UNION SELECT 2 UNION ALL SELECT 2; + +SELECT 1.1 AS two UNION SELECT 2.2; + +-- Mixed types + +SELECT 1.1 AS two UNION SELECT 2; + +SELECT 1 AS two UNION SELECT 2.2; + +SELECT 1 AS one UNION SELECT 1.1; + +SELECT 1.1 AS two UNION ALL SELECT 2; + +SELECT 1 AS two UNION ALL SELECT 1; + +SELECT 1 AS three UNION SELECT 2 UNION SELECT 3; + +SELECT 1 AS two UNION SELECT 2 UNION SELECT 2; + +SELECT 1 AS three UNION SELECT 2 UNION ALL SELECT 2; + +-- +-- Try testing from tables... +-- + +SELECT f1 AS five FROM FLOAT8_TBL +UNION +SELECT f1 FROM FLOAT8_TBL; + +SELECT f1 AS ten FROM FLOAT8_TBL +UNION ALL +SELECT f1 FROM FLOAT8_TBL; + +SELECT f1 AS nine FROM FLOAT8_TBL +UNION +SELECT f1 FROM INT4_TBL; + +SELECT f1 AS ten FROM FLOAT8_TBL +UNION ALL +SELECT f1 FROM INT4_TBL; + +SELECT f1 AS five FROM FLOAT8_TBL + WHERE f1 BETWEEN -1e6 AND 1e6 +UNION +SELECT f1 FROM INT4_TBL + WHERE f1 BETWEEN 0 AND 1000000; + +SELECT f1 AS five FROM VARCHAR_TBL +UNION +SELECT f1 FROM CHAR_TBL; + +SELECT f1 AS three FROM VARCHAR_TBL +UNION +SELECT TRIM(TRAILING FROM f1) FROM CHAR_TBL; + +SELECT f1 AS eight FROM VARCHAR_TBL +UNION ALL +SELECT f1 FROM CHAR_TBL; + +SELECT f1 AS five FROM TEXT_TBL +UNION +SELECT f1 FROM VARCHAR_TBL +UNION +SELECT TRIM(TRAILING FROM f1) FROM CHAR_TBL; + -- 2.40.0