Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit910eb61

Browse files
committed
Only evaluate default values as required when doing COPY FROM
Commit9f8377f was a little too eager in fetching default values.Normally this would not matter, but if the default value is not validfor the type (e.g. a varchar that's too long) it caused an unnecessaryerror.Complaint and fix from Laurenz AlbeBackpatch to release 16.Discussion:https://postgr.es/m/75a7b7483aeb331aa017328d606d568fc715b90d.camel@cybertec.at
1 parentd5c5312 commit910eb61

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

‎src/backend/commands/copyfrom.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,14 @@ BeginCopyFrom(ParseState *pstate,
15691569
/* Get default info if available */
15701570
defexprs[attnum-1]=NULL;
15711571

1572-
if (!att->attgenerated)
1572+
/*
1573+
* We only need the default values for columns that do not appear in
1574+
* the column list, unless the DEFAULT option was given. We never need
1575+
* default values for generated columns.
1576+
*/
1577+
if ((cstate->opts.default_print!=NULL||
1578+
!list_member_int(cstate->attnumlist,attnum))&&
1579+
!att->attgenerated)
15731580
{
15741581
Expr*defexpr= (Expr*)build_column_default(cstate->rel,
15751582
attnum);

‎src/test/regress/expected/copy.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,20 @@ SELECT * FROM header_copytest ORDER BY a;
240240
(5 rows)
241241

242242
drop table header_copytest;
243+
-- test COPY with overlong column defaults
244+
create temp table oversized_column_default (
245+
col1 varchar(5) DEFAULT 'more than 5 chars',
246+
col2 varchar(5));
247+
-- normal COPY should work
248+
copy oversized_column_default from stdin;
249+
-- error if the column is excluded
250+
copy oversized_column_default (col2) from stdin;
251+
ERROR: value too long for type character varying(5)
252+
\.
253+
invalid command \.
254+
-- error if the DEFAULT option is given
255+
copy oversized_column_default from stdin (default '');
256+
ERROR: value too long for type character varying(5)
257+
\.
258+
invalid command \.
259+
drop table oversized_column_default;

‎src/test/regress/sql/copy.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,18 @@ acb
268268

269269
SELECT*FROM header_copytestORDER BY a;
270270
droptable header_copytest;
271+
272+
-- test COPY with overlong column defaults
273+
create temp table oversized_column_default (
274+
col1varchar(5) DEFAULT'more than 5 chars',
275+
col2varchar(5));
276+
-- normal COPY should work
277+
copy oversized_column_defaultfrom stdin;
278+
\.
279+
-- error if the column is excluded
280+
copy oversized_column_default (col2)from stdin;
281+
\.
282+
-- error if the DEFAULT option is given
283+
copy oversized_column_defaultfrom stdin (default'');
284+
\.
285+
droptable oversized_column_default;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp