5 -- Build a table for testing
6 -- (This temporarily hides the table created in test_setup.sql)
8 CREATE TEMP TABLE VARCHAR_TBL(f1 varchar(1));
9 INSERT INTO VARCHAR_TBL (f1) VALUES ('a');
10 INSERT INTO VARCHAR_TBL (f1) VALUES ('A');
11 -- any of the following three input formats are acceptable
12 INSERT INTO VARCHAR_TBL (f1) VALUES ('1');
13 INSERT INTO VARCHAR_TBL (f1) VALUES (2);
14 INSERT INTO VARCHAR_TBL (f1) VALUES ('3');
16 INSERT INTO VARCHAR_TBL (f1) VALUES ('');
17 -- try varchar's of greater than 1 length
18 INSERT INTO VARCHAR_TBL (f1) VALUES ('cd');
19 ERROR: value too long for type character varying(1)
20 INSERT INTO VARCHAR_TBL (f1) VALUES ('c ');
21 SELECT * FROM VARCHAR_TBL;
96 DROP TABLE VARCHAR_TBL;
98 -- Now test longer arrays of char
100 -- This varchar_tbl was already created and filled in test_setup.sql.
101 -- Here we just try to insert bad values.
103 INSERT INTO VARCHAR_TBL (f1) VALUES ('abcde');
104 ERROR: value too long for type character varying(4)
105 SELECT * FROM VARCHAR_TBL;
114 -- Also try it with non-error-throwing API
115 SELECT pg_input_is_valid('abcd ', 'varchar(4)');
121 SELECT pg_input_is_valid('abcde', 'varchar(4)');
127 SELECT * FROM pg_input_error_info('abcde', 'varchar(4)');
128 message | detail | hint | sql_error_code
129 ----------------------------------------------+--------+------+----------------
130 value too long for type character varying(4) | | | 22001