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

Commitf052307

Browse files
committed
Revert "Allow ON CONFLICT .. DO NOTHING on a partitioned table."
This reverts commit8355a01, whichturns out to have been a misguided effort. We can't really supportthis in a partitioning hierarchy after all for exactly the reasonsstated in the documentation removed by that commit. It's stillpossible to use ON CONFLICT .. DO NOTHING (or for that matter ONCONFLICT .. DO UPDATE) on individual partitions if desired, butbut to allow this on a partitioned table implies that we have someway of evaluating uniqueness across the whole partitioninghierarchy, which is false.Shinoda Noriyoshi noticed that the old code was crashing (which wecould fix, though not in a nice way) and Amit Langote realizedthat this was indicative of a fundamental problem with the commitbeing reverted here.Discussion:http://postgr.es/m/ff3dc21d-7204-c09c-50ac-cf11a8c45c81@lab.ntt.co.jp
1 parentc94e694 commitf052307

File tree

4 files changed

+10
-26
lines changed

4 files changed

+10
-26
lines changed

‎doc/src/sgml/ddl.sgml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,12 +3854,8 @@ ANALYZE measurement;
38543854

38553855
<listitem>
38563856
<para>
3857-
Using the <literal>ON CONFLICT</literal> clause with partitioned tables
3858-
will cause an error if <literal>DO UPDATE</literal> is specified as the
3859-
alternative action, because unique or exclusion constraints can only be
3860-
created on individual partitions. There is no support for enforcing
3861-
uniqueness (or an exclusion constraint) across an entire partitioning
3862-
hierarchy.
3857+
<command>INSERT</command> statements with <literal>ON CONFLICT</>
3858+
clause are currently not allowed on partitioned tables.
38633859
</para>
38643860
</listitem>
38653861

‎src/backend/parser/analyze.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,16 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
842842

843843
/* Process ON CONFLICT, if any. */
844844
if (stmt->onConflictClause)
845+
{
846+
/* Bail out if target relation is partitioned table */
847+
if (pstate->p_target_rangetblentry->relkind==RELKIND_PARTITIONED_TABLE)
848+
ereport(ERROR,
849+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
850+
errmsg("ON CONFLICT clause is not supported with partitioned tables")));
851+
845852
qry->onConflict=transformOnConflictClause(pstate,
846853
stmt->onConflictClause);
854+
}
847855

848856
/*
849857
* If we have a RETURNING clause, we need to add the target relation to

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -786,13 +786,3 @@ select * from selfconflict;
786786
(3 rows)
787787

788788
drop table selfconflict;
789-
-- check that the following works:
790-
-- insert into partitioned_table on conflict do nothing
791-
create table parted_conflict_test (a int, b char) partition by list (a);
792-
create table parted_conflict_test_1 partition of parted_conflict_test for values in (1);
793-
insert into parted_conflict_test values (1, 'a') on conflict do nothing;
794-
insert into parted_conflict_test values (1, 'a') on conflict do nothing;
795-
-- however, on conflict do update not supported yet
796-
insert into parted_conflict_test values (1) on conflict (a) do update set b = excluded.b where excluded.a = 1;
797-
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
798-
drop table parted_conflict_test, parted_conflict_test_1;

‎src/test/regress/sql/insert_conflict.sql

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,3 @@ commit;
471471
select*from selfconflict;
472472

473473
droptable selfconflict;
474-
475-
-- check that the following works:
476-
-- insert into partitioned_table on conflict do nothing
477-
createtableparted_conflict_test (aint, bchar) partition by list (a);
478-
createtableparted_conflict_test_1 partition of parted_conflict_test forvaluesin (1);
479-
insert into parted_conflict_testvalues (1,'a')on conflict do nothing;
480-
insert into parted_conflict_testvalues (1,'a')on conflict do nothing;
481-
-- however, on conflict do update not supported yet
482-
insert into parted_conflict_testvalues (1)on conflict (a) doupdateset b=excluded.bwhereexcluded.a=1;
483-
droptable parted_conflict_test, parted_conflict_test_1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp