Correct grammar in picksplit debug messages
[PostgreSQL.git] / src / test / regress / sql / copy2.sql
blob7c23ba253c4e28a47af195963ffd3d8094b829da
1 CREATE TEMP TABLE x (
2         a serial,
3         b int,
4         c text not null default 'stuff',
5         d text,
6         e text
7 ) WITH OIDS;
9 CREATE FUNCTION fn_x_before () RETURNS TRIGGER AS '
10   BEGIN
11                 NEW.e := ''before trigger fired''::text;
12                 return NEW;
13         END;
14 ' LANGUAGE plpgsql;
16 CREATE FUNCTION fn_x_after () RETURNS TRIGGER AS '
17   BEGIN
18                 UPDATE x set e=''after trigger fired'' where c=''stuff'';
19                 return NULL;
20         END;
21 ' LANGUAGE plpgsql;
23 CREATE TRIGGER trg_x_after AFTER INSERT ON x
24 FOR EACH ROW EXECUTE PROCEDURE fn_x_after();
26 CREATE TRIGGER trg_x_before BEFORE INSERT ON x
27 FOR EACH ROW EXECUTE PROCEDURE fn_x_before();
29 COPY x (a, b, c, d, e) from stdin;
30 9999    \N      \\N     \NN     \N
31 10000   21      31      41      51
34 COPY x (b, d) from stdin;
35 1       test_1
38 COPY x (b, d) from stdin;
39 2       test_2
40 3       test_3
41 4       test_4
42 5       test_5
45 COPY x (a, b, c, d, e) from stdin;
46 10001   22      32      42      52
47 10002   23      33      43      53
48 10003   24      34      44      54
49 10004   25      35      45      55
50 10005   26      36      46      56
53 -- non-existent column in column list: should fail
54 COPY x (xyz) from stdin;
56 -- too many columns in column list: should fail
57 COPY x (a, b, c, d, e, d, c) from stdin;
59 -- missing data: should fail
60 COPY x from stdin;
63 COPY x from stdin;
64 2000    230     23      23
66 COPY x from stdin;
67 2001    231     \N      \N
70 -- extra data: should fail
71 COPY x from stdin;
72 2002    232     40      50      60      70      80
75 -- various COPY options: delimiters, oids, NULL string
76 COPY x (b, c, d, e) from stdin with oids delimiter ',' null 'x';
77 500000,x,45,80,90
78 500001,x,\x,\\x,\\\x
79 500002,x,\,,\\\,,\\
82 COPY x from stdin WITH DELIMITER AS ';' NULL AS '';
83 3000;;c;;
86 COPY x from stdin WITH DELIMITER AS ':' NULL AS E'\\X';
87 4000:\X:C:\X:\X
88 4001:1:empty::
89 4002:2:null:\X:\X
90 4003:3:Backslash:\\:\\
91 4004:4:BackslashX:\\X:\\X
92 4005:5:N:\N:\N
93 4006:6:BackslashN:\\N:\\N
94 4007:7:XX:\XX:\XX
95 4008:8:Delimiter:\::\:
98 -- check results of copy in
99 SELECT * FROM x;
101 -- COPY w/ oids on a table w/o oids should fail
102 CREATE TABLE no_oids (
103         a       int,
104         b       int
105 ) WITHOUT OIDS;
107 INSERT INTO no_oids (a, b) VALUES (5, 10);
108 INSERT INTO no_oids (a, b) VALUES (20, 30);
110 -- should fail
111 COPY no_oids FROM stdin WITH OIDS;
112 COPY no_oids TO stdout WITH OIDS;
114 -- check copy out
115 COPY x TO stdout;
116 COPY x (c, e) TO stdout;
117 COPY x (b, e) TO stdout WITH NULL 'I''m null';
119 CREATE TEMP TABLE y (
120         col1 text,
121         col2 text
124 INSERT INTO y VALUES ('Jackson, Sam', E'\\h');
125 INSERT INTO y VALUES ('It is "perfect".',E'\t');
126 INSERT INTO y VALUES ('', NULL);
128 COPY y TO stdout WITH CSV;
129 COPY y TO stdout WITH CSV QUOTE '''' DELIMITER '|';
130 COPY y TO stdout WITH CSV FORCE QUOTE col2 ESCAPE E'\\';
132 --test that we read consecutive LFs properly
134 CREATE TEMP TABLE testnl (a int, b text, c int);
136 COPY testnl FROM stdin CSV;
137 1,"a field with two LFs
139 inside",2
142 -- test end of copy marker
143 CREATE TEMP TABLE testeoc (a text);
145 COPY testeoc FROM stdin CSV;
148 c\.d
149 "\."
152 COPY testeoc TO stdout CSV;
154 DROP TABLE x, y;
155 DROP FUNCTION fn_x_before();
156 DROP FUNCTION fn_x_after();