4 c text not null default 'stuff',
9 CREATE FUNCTION fn_x_before () RETURNS TRIGGER AS '
11 NEW.e := ''before trigger fired''::text;
16 CREATE FUNCTION fn_x_after () RETURNS TRIGGER AS '
18 UPDATE x set e=''after trigger fired'' where c=''stuff'';
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;
34 COPY x (b, d) from stdin;
38 COPY x (b, d) from stdin;
45 COPY x (a, b, c, d, e) from stdin;
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
70 -- extra data: should fail
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';
82 COPY x from stdin WITH DELIMITER AS ';' NULL AS '';
86 COPY x from stdin WITH DELIMITER AS ':' NULL AS E'\\X';
90 4003:3:Backslash:\\:\\
91 4004:4:BackslashX:\\X:\\X
93 4006:6:BackslashN:\\N:\\N
95 4008:8:Delimiter:\::\:
98 -- check results of copy in
101 -- COPY w/ oids on a table w/o oids should fail
102 CREATE TABLE no_oids (
107 INSERT INTO no_oids (a, b) VALUES (5, 10);
108 INSERT INTO no_oids (a, b) VALUES (20, 30);
111 COPY no_oids FROM stdin WITH OIDS;
112 COPY no_oids TO stdout WITH OIDS;
116 COPY x (c, e) TO stdout;
117 COPY x (b, e) TO stdout WITH NULL 'I''m null';
119 CREATE TEMP TABLE y (
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
142 -- test end of copy marker
143 CREATE TEMP TABLE testeoc (a text);
145 COPY testeoc FROM stdin CSV;
152 COPY testeoc TO stdout CSV;
155 DROP FUNCTION fn_x_before();
156 DROP FUNCTION fn_x_after();