mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-24 18:55:04 +08:00
Add tests for varchar() and combinations of string types.
This commit is contained in:
parent
1d7b6f14e2
commit
7a86a2a9e5
17
src/test/regress/expected/strings.out
Normal file
17
src/test/regress/expected/strings.out
Normal file
@ -0,0 +1,17 @@
|
||||
QUERY: SELECT 'first line'
|
||||
' - next line'
|
||||
' - third line'
|
||||
AS "Three lines to one";
|
||||
Three lines to one
|
||||
-----------------------------------
|
||||
first line - next line - third line
|
||||
(1 row)
|
||||
|
||||
QUERY: SELECT 'first line'
|
||||
' - next line' /* this comment is not allowed here */
|
||||
' - third line';
|
||||
WARN:parser: parse error at or near "'"
|
||||
QUERY: SELECT text(f1) FROM CHAR_TBL;
|
||||
WARN:func_get_detail: function text(bpchar) does not exist
|
||||
QUERY: SELECT text(f1) FROM VARCHAR_TBL;
|
||||
WARN:func_get_detail: function text(varchar) does not exist
|
98
src/test/regress/expected/varchar.out
Normal file
98
src/test/regress/expected/varchar.out
Normal file
@ -0,0 +1,98 @@
|
||||
QUERY: CREATE TABLE VARCHAR_TBL(f1 varchar(1));
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('A');
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('1');
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES (2);
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('3');
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('');
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('cd');
|
||||
QUERY: SELECT '' AS seven, VARCHAR_TBL.*;
|
||||
seven|f1
|
||||
-----+--
|
||||
|a
|
||||
|A
|
||||
|1
|
||||
|2
|
||||
|3
|
||||
|
|
||||
|c
|
||||
(7 rows)
|
||||
|
||||
QUERY: SELECT '' AS six, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 <> 'a';
|
||||
six|f1
|
||||
---+--
|
||||
|A
|
||||
|1
|
||||
|2
|
||||
|3
|
||||
|
|
||||
|c
|
||||
(6 rows)
|
||||
|
||||
QUERY: SELECT '' AS one, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 = 'a';
|
||||
one|f1
|
||||
---+--
|
||||
|a
|
||||
(1 row)
|
||||
|
||||
QUERY: SELECT '' AS five, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 < 'a';
|
||||
five|f1
|
||||
----+--
|
||||
|A
|
||||
|1
|
||||
|2
|
||||
|3
|
||||
|
|
||||
(5 rows)
|
||||
|
||||
QUERY: SELECT '' AS six, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 <= 'a';
|
||||
six|f1
|
||||
---+--
|
||||
|a
|
||||
|A
|
||||
|1
|
||||
|2
|
||||
|3
|
||||
|
|
||||
(6 rows)
|
||||
|
||||
QUERY: SELECT '' AS one, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 > 'a';
|
||||
one|f1
|
||||
---+--
|
||||
|c
|
||||
(1 row)
|
||||
|
||||
QUERY: SELECT '' AS two, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 >= 'a';
|
||||
two|f1
|
||||
---+--
|
||||
|a
|
||||
|c
|
||||
(2 rows)
|
||||
|
||||
QUERY: DROP TABLE VARCHAR_TBL;
|
||||
QUERY: CREATE TABLE VARCHAR_TBL(f1 varchar(4));
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('ab');
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('abcd');
|
||||
QUERY: INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde');
|
||||
QUERY: SELECT '' AS four, VARCHAR_TBL.*;
|
||||
four|f1
|
||||
----+----
|
||||
|a
|
||||
|ab
|
||||
|abcd
|
||||
|abcd
|
||||
(4 rows)
|
||||
|
23
src/test/regress/sql/strings.sql
Normal file
23
src/test/regress/sql/strings.sql
Normal file
@ -0,0 +1,23 @@
|
||||
--
|
||||
-- Test various data entry syntaxes.
|
||||
--
|
||||
|
||||
-- SQL92 string continuation syntax
|
||||
SELECT 'first line'
|
||||
' - next line'
|
||||
' - third line'
|
||||
AS "Three lines to one";
|
||||
|
||||
-- illegal string continuation syntax
|
||||
SELECT 'first line'
|
||||
' - next line' /* this comment is not allowed here */
|
||||
' - third line';
|
||||
|
||||
--
|
||||
-- test conversions between various string types
|
||||
--
|
||||
|
||||
SELECT text(f1) FROM CHAR_TBL;
|
||||
|
||||
SELECT text(f1) FROM VARCHAR_TBL;
|
||||
|
64
src/test/regress/sql/varchar.sql
Normal file
64
src/test/regress/sql/varchar.sql
Normal file
@ -0,0 +1,64 @@
|
||||
-- ****************** test built-in type varchar **************
|
||||
--
|
||||
|
||||
CREATE TABLE VARCHAR_TBL(f1 varchar(1));
|
||||
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
|
||||
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('A');
|
||||
|
||||
-- any of the following three input formats are acceptable
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('1');
|
||||
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES (2);
|
||||
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('3');
|
||||
|
||||
-- zero-length char
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('');
|
||||
|
||||
-- try varchar's of greater than 1 length
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('cd');
|
||||
|
||||
|
||||
SELECT '' AS seven, VARCHAR_TBL.*;
|
||||
|
||||
SELECT '' AS six, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 <> 'a';
|
||||
|
||||
SELECT '' AS one, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 = 'a';
|
||||
|
||||
SELECT '' AS five, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 < 'a';
|
||||
|
||||
SELECT '' AS six, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 <= 'a';
|
||||
|
||||
SELECT '' AS one, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 > 'a';
|
||||
|
||||
SELECT '' AS two, c.*
|
||||
FROM VARCHAR_TBL c
|
||||
WHERE c.f1 >= 'a';
|
||||
|
||||
DROP TABLE VARCHAR_TBL;
|
||||
|
||||
--
|
||||
-- Now test longer arrays of char
|
||||
--
|
||||
|
||||
CREATE TABLE VARCHAR_TBL(f1 varchar(4));
|
||||
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('ab');
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('abcd');
|
||||
INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde');
|
||||
|
||||
SELECT '' AS four, VARCHAR_TBL.*;
|
||||
|
Loading…
Reference in New Issue
Block a user