diff options
| author | Peter Eisentraut <peter_e@gmx.net> | 2001-05-21 16:54:46 +0000 |
|---|---|---|
| committer | Peter Eisentraut <peter_e@gmx.net> | 2001-05-21 16:54:46 +0000 |
| commit | 5546ec289bc75eac0be689d9a36950f702b4c5f6 (patch) | |
| tree | 69701ea9ff508912677adb14be9ce5d53702ea17 /src/test | |
| parent | d27f363e3fceb7612997ae89a8fc84de6754a213 (diff) | |
| download | postgresql-5546ec289bc75eac0be689d9a36950f702b4c5f6.tar.gz | |
Make char(n) and varchar(n) types raise an error if the inserted string is
too long. While I was adjusting the regression tests I moved the array
things all into array.sql, to make things more manageable.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/arrays.out | 30 | ||||
| -rw-r--r-- | src/test/regress/expected/char.out | 5 | ||||
| -rw-r--r-- | src/test/regress/expected/create_misc.out | 17 | ||||
| -rw-r--r-- | src/test/regress/expected/create_table.out | 9 | ||||
| -rw-r--r-- | src/test/regress/expected/strings.out | 16 | ||||
| -rw-r--r-- | src/test/regress/expected/varchar.out | 4 | ||||
| -rw-r--r-- | src/test/regress/sql/arrays.sql | 34 | ||||
| -rw-r--r-- | src/test/regress/sql/char.sql | 4 | ||||
| -rw-r--r-- | src/test/regress/sql/create_misc.sql | 24 | ||||
| -rw-r--r-- | src/test/regress/sql/create_table.sql | 10 | ||||
| -rw-r--r-- | src/test/regress/sql/strings.sql | 6 | ||||
| -rw-r--r-- | src/test/regress/sql/varchar.sql | 3 |
12 files changed, 87 insertions, 75 deletions
diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.out index b687838064..74c1008d90 100644 --- a/src/test/regress/expected/arrays.out +++ b/src/test/regress/expected/arrays.out @@ -1,6 +1,32 @@ -- -- ARRAYS -- +CREATE TABLE arrtest ( + a int2[], + b int4[][][], + c name[], + d text[][], + e float8[], + f char(5)[], + g varchar(5)[] +); +-- +-- only this array as a 0-based 'e', the others are 1-based. +-- 'e' is also a large object. +-- +INSERT INTO arrtest (a[5], b[2][1][2], c, d, f, g) + VALUES ('{1,2,3,4,5}', '{{{},{1,2}}}', '{}', '{}', '{}', '{}'); +UPDATE arrtest SET e[0] = '1.1'; +UPDATE arrtest SET e[1] = '2.2'; +INSERT INTO arrtest (f) + VALUES ('{"too long"}'); +ERROR: value too long for type character(5) +INSERT INTO arrtest (a, b[2][2][1], c, d, e, f, g) + VALUES ('{11,12,23}', '{{3,4},{4,5}}', '{"foobar"}', + '{{"elt1", "elt2"}}', '{"3.4", "6.7"}', + '{"abc","abcde"}', '{"abc","abcde"}'); +INSERT INTO arrtest (a, b[1][2][2], c, d[2][1]) + VALUES ('{}', '{3,4}', '{foo,bar}', '{bar,foo}'); SELECT * FROM arrtest; a | b | c | d | e | f | g -------------+-----------------+---------------+-------------------+---------------+-------------------+----------------- @@ -75,8 +101,8 @@ SELECT a,b,c FROM arrtest; a | b | c ---------------+-----------------------+----------------------- {16,25,3,4,5} | {{{113,142},{1,147}}} | {} - {16,25,23} | {{3,4},{4,5}} | {"foobar","new_word"} {} | {3,4} | {"foo","new_word"} + {16,25,23} | {{3,4},{4,5}} | {"foobar","new_word"} (3 rows) SELECT a[1:3], @@ -87,7 +113,7 @@ SELECT a[1:3], a | b | c | d ------------+-----------------------+-----------------------+------------ {16,25,3} | {{{113,142},{1,147}}} | | - {16,25,23} | | {"foobar","new_word"} | {{"elt2"}} | | {"foo","new_word"} | + {16,25,23} | | {"foobar","new_word"} | {{"elt2"}} (3 rows) diff --git a/src/test/regress/expected/char.out b/src/test/regress/expected/char.out index 63606fba2d..0c46e07976 100644 --- a/src/test/regress/expected/char.out +++ b/src/test/regress/expected/char.out @@ -1,6 +1,5 @@ -- -- CHAR --- all inputs are SILENTLY truncated at 1 character -- -- fixed-length by value -- internally passed by value if <= 4 bytes in storage @@ -24,6 +23,8 @@ INSERT INTO CHAR_TBL (f1) VALUES ('3'); INSERT INTO CHAR_TBL (f1) VALUES (''); -- try char's of greater than 1 length INSERT INTO CHAR_TBL (f1) VALUES ('cd'); +ERROR: value too long for type character(1) +INSERT INTO CHAR_TBL (f1) VALUES ('c '); SELECT '' AS seven, CHAR_TBL.*; seven | f1 -------+---- @@ -108,6 +109,8 @@ INSERT INTO CHAR_TBL (f1) VALUES ('a'); INSERT INTO CHAR_TBL (f1) VALUES ('ab'); INSERT INTO CHAR_TBL (f1) VALUES ('abcd'); INSERT INTO CHAR_TBL (f1) VALUES ('abcde'); +ERROR: value too long for type character(4) +INSERT INTO CHAR_TBL (f1) VALUES ('abcd '); SELECT '' AS four, CHAR_TBL.*; four | f1 ------+------ diff --git a/src/test/regress/expected/create_misc.out b/src/test/regress/expected/create_misc.out index add55bc767..c7600fd13f 100644 --- a/src/test/regress/expected/create_misc.out +++ b/src/test/regress/expected/create_misc.out @@ -121,23 +121,6 @@ INSERT INTO f_star (class, f) VALUES ('f', '(11111111,33333333),(22222222,44444444)'::polygon); INSERT INTO f_star (class) VALUES ('f'); -- --- ARRAYS --- --- --- only this array as a 0-based 'e', the others are 1-based. --- 'e' is also a large object. --- -INSERT INTO arrtest (a[5], b[2][1][2], c, d, f, g) - VALUES ('{1,2,3,4,5}', '{{{},{1,2}}}', '{}', '{}', '{}', '{}'); -UPDATE arrtest SET e[0] = '1.1'; -UPDATE arrtest SET e[1] = '2.2'; -INSERT INTO arrtest (a, b[2][2][1], c, d, e, f, g) - VALUES ('{11,12,23}', '{{3,4},{4,5}}', '{"foobar"}', - '{{"elt1", "elt2"}}', '{"3.4", "6.7"}', - '{"abc","abcdefgh"}', '{"abc","abcdefgh"}'); -INSERT INTO arrtest (a, b[1][2][2], c, d[2][1]) - VALUES ('{}', '{3,4}', '{foo,bar}', '{bar,foo}'); --- -- for internal portal (cursor) tests -- CREATE TABLE iportaltest ( diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index a0ddd5ef60..3734960691 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -147,15 +147,6 @@ CREATE TABLE aggtest ( a int2, b float4 ); -CREATE TABLE arrtest ( - a int2[], - b int4[][][], - c name[], - d text[][], - e float8[], - f char(5)[], - g varchar(5)[] -); CREATE TABLE hash_i4_heap ( seqno int4, random int4 diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out index e59ba8e1df..7562a25fdc 100644 --- a/src/test/regress/expected/strings.out +++ b/src/test/regress/expected/strings.out @@ -45,11 +45,13 @@ SELECT CAST(name 'namefield' AS text) AS "text(name)"; namefield (1 row) -SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL; - char(text) ------------- - doh! - hi de ho n +SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL; -- fail +ERROR: value too long for type character(10) +SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL; + char(text) +---------------------- + doh! + hi de ho neighbor (2 rows) SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL; @@ -479,10 +481,10 @@ SELECT text 'text' || ' and unknown' AS "Concat text to unknown type"; text and unknown (1 row) -SELECT text 'text' || char(10) ' and characters' AS "Concat text to char"; +SELECT text 'text' || char(20) ' and characters' AS "Concat text to char"; Concat text to char --------------------- - text and chara + text and characters (1 row) SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar"; diff --git a/src/test/regress/expected/varchar.out b/src/test/regress/expected/varchar.out index 5f4c0f1f56..e33782eed7 100644 --- a/src/test/regress/expected/varchar.out +++ b/src/test/regress/expected/varchar.out @@ -12,6 +12,8 @@ INSERT INTO VARCHAR_TBL (f1) VALUES ('3'); INSERT INTO VARCHAR_TBL (f1) VALUES (''); -- try varchar's of greater than 1 length INSERT INTO VARCHAR_TBL (f1) VALUES ('cd'); +ERROR: value too long for type character varying(1) +INSERT INTO VARCHAR_TBL (f1) VALUES ('c '); SELECT '' AS seven, VARCHAR_TBL.*; seven | f1 -------+---- @@ -96,6 +98,8 @@ 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'); +ERROR: value too long for type character varying(4) +INSERT INTO VARCHAR_TBL (f1) VALUES ('abcd '); SELECT '' AS four, VARCHAR_TBL.*; four | f1 ------+------ diff --git a/src/test/regress/sql/arrays.sql b/src/test/regress/sql/arrays.sql index 3b02acf642..a3300eae12 100644 --- a/src/test/regress/sql/arrays.sql +++ b/src/test/regress/sql/arrays.sql @@ -2,6 +2,40 @@ -- ARRAYS -- +CREATE TABLE arrtest ( + a int2[], + b int4[][][], + c name[], + d text[][], + e float8[], + f char(5)[], + g varchar(5)[] +); + +-- +-- only this array as a 0-based 'e', the others are 1-based. +-- 'e' is also a large object. +-- + +INSERT INTO arrtest (a[5], b[2][1][2], c, d, f, g) + VALUES ('{1,2,3,4,5}', '{{{},{1,2}}}', '{}', '{}', '{}', '{}'); + +UPDATE arrtest SET e[0] = '1.1'; + +UPDATE arrtest SET e[1] = '2.2'; + +INSERT INTO arrtest (f) + VALUES ('{"too long"}'); + +INSERT INTO arrtest (a, b[2][2][1], c, d, e, f, g) + VALUES ('{11,12,23}', '{{3,4},{4,5}}', '{"foobar"}', + '{{"elt1", "elt2"}}', '{"3.4", "6.7"}', + '{"abc","abcde"}', '{"abc","abcde"}'); + +INSERT INTO arrtest (a, b[1][2][2], c, d[2][1]) + VALUES ('{}', '{3,4}', '{foo,bar}', '{bar,foo}'); + + SELECT * FROM arrtest; SELECT arrtest.a[1], diff --git a/src/test/regress/sql/char.sql b/src/test/regress/sql/char.sql index ba7167fc65..049f22fad3 100644 --- a/src/test/regress/sql/char.sql +++ b/src/test/regress/sql/char.sql @@ -1,6 +1,5 @@ -- -- CHAR --- all inputs are SILENTLY truncated at 1 character -- -- fixed-length by value @@ -30,6 +29,7 @@ INSERT INTO CHAR_TBL (f1) VALUES (''); -- try char's of greater than 1 length INSERT INTO CHAR_TBL (f1) VALUES ('cd'); +INSERT INTO CHAR_TBL (f1) VALUES ('c '); SELECT '' AS seven, CHAR_TBL.*; @@ -70,6 +70,6 @@ INSERT INTO CHAR_TBL (f1) VALUES ('a'); INSERT INTO CHAR_TBL (f1) VALUES ('ab'); INSERT INTO CHAR_TBL (f1) VALUES ('abcd'); INSERT INTO CHAR_TBL (f1) VALUES ('abcde'); +INSERT INTO CHAR_TBL (f1) VALUES ('abcd '); SELECT '' AS four, CHAR_TBL.*; - diff --git a/src/test/regress/sql/create_misc.sql b/src/test/regress/sql/create_misc.sql index cd73f64060..078450a754 100644 --- a/src/test/regress/sql/create_misc.sql +++ b/src/test/regress/sql/create_misc.sql @@ -188,30 +188,6 @@ INSERT INTO f_star (class, f) INSERT INTO f_star (class) VALUES ('f'); --- --- ARRAYS --- - --- --- only this array as a 0-based 'e', the others are 1-based. --- 'e' is also a large object. --- - -INSERT INTO arrtest (a[5], b[2][1][2], c, d, f, g) - VALUES ('{1,2,3,4,5}', '{{{},{1,2}}}', '{}', '{}', '{}', '{}'); - -UPDATE arrtest SET e[0] = '1.1'; - -UPDATE arrtest SET e[1] = '2.2'; - -INSERT INTO arrtest (a, b[2][2][1], c, d, e, f, g) - VALUES ('{11,12,23}', '{{3,4},{4,5}}', '{"foobar"}', - '{{"elt1", "elt2"}}', '{"3.4", "6.7"}', - '{"abc","abcdefgh"}', '{"abc","abcdefgh"}'); - -INSERT INTO arrtest (a, b[1][2][2], c, d[2][1]) - VALUES ('{}', '{3,4}', '{foo,bar}', '{bar,foo}'); - -- -- for internal portal (cursor) tests diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql index fe54708944..b6a0a8fe60 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -172,16 +172,6 @@ CREATE TABLE aggtest ( b float4 ); -CREATE TABLE arrtest ( - a int2[], - b int4[][][], - c name[], - d text[][], - e float8[], - f char(5)[], - g varchar(5)[] -); - CREATE TABLE hash_i4_heap ( seqno int4, random int4 diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql index f1c7d5f298..56510f83dd 100644 --- a/src/test/regress/sql/strings.sql +++ b/src/test/regress/sql/strings.sql @@ -25,7 +25,9 @@ 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(10)) AS "char(text)" FROM TEXT_TBL; +SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL; -- fail + +SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL; SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL; @@ -158,7 +160,7 @@ SELECT 'unknown' || ' and unknown' AS "Concat unknown types"; SELECT text 'text' || ' and unknown' AS "Concat text to unknown type"; -SELECT text 'text' || char(10) ' and characters' AS "Concat text to char"; +SELECT text 'text' || char(20) ' and characters' AS "Concat text to char"; SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar"; diff --git a/src/test/regress/sql/varchar.sql b/src/test/regress/sql/varchar.sql index e28c8f9b93..70fa8afb4b 100644 --- a/src/test/regress/sql/varchar.sql +++ b/src/test/regress/sql/varchar.sql @@ -20,6 +20,7 @@ INSERT INTO VARCHAR_TBL (f1) VALUES (''); -- try varchar's of greater than 1 length INSERT INTO VARCHAR_TBL (f1) VALUES ('cd'); +INSERT INTO VARCHAR_TBL (f1) VALUES ('c '); SELECT '' AS seven, VARCHAR_TBL.*; @@ -60,6 +61,6 @@ 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'); +INSERT INTO VARCHAR_TBL (f1) VALUES ('abcd '); SELECT '' AS four, VARCHAR_TBL.*; - |
