Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f052307

Browse files
committed
Revert "Allow ON CONFLICT .. DO NOTHING on a partitioned table."
This reverts commit 8355a01, which turns out to have been a misguided effort. We can't really support this in a partitioning hierarchy after all for exactly the reasons stated in the documentation removed by that commit. It's still possible to use ON CONFLICT .. DO NOTHING (or for that matter ON CONFLICT .. DO UPDATE) on individual partitions if desired, but but to allow this on a partitioned table implies that we have some way of evaluating uniqueness across the whole partitioning hierarchy, which is false. Shinoda Noriyoshi noticed that the old code was crashing (which we could fix, though not in a nice way) and Amit Langote realized that this was indicative of a fundamental problem with the commit being reverted here. Discussion: http://postgr.es/m/ff3dc21d-7204-c09c-50ac-cf11a8c45c81@lab.ntt.co.jp
1 parent c94e694 commit f052307

File tree

4 files changed

+10
-26
lines changed

4 files changed

+10
-26
lines changed

doc/src/sgml/ddl.sgml

+2-6
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

+8
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

-10
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

-10
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,3 @@ commit;
471471
select * from selfconflict;
472472

473473
drop table selfconflict;
474-
475-
-- check that the following works:
476-
-- insert into partitioned_table on conflict do nothing
477-
create table parted_conflict_test (a int, b char) partition by list (a);
478-
create table parted_conflict_test_1 partition of parted_conflict_test for values in (1);
479-
insert into parted_conflict_test values (1, 'a') on conflict do nothing;
480-
insert into parted_conflict_test values (1, 'a') on conflict do nothing;
481-
-- however, on conflict do update not supported yet
482-
insert into parted_conflict_test values (1) on conflict (a) do update set b = excluded.b where excluded.a = 1;
483-
drop table parted_conflict_test, parted_conflict_test_1;

0 commit comments

Comments
 (0)