From: Олег Самойлов <splarv@ya.ru>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Can not drop partition if exist foreign keys
Date: Wed, 11 Oct 2023 14:08:54 +0300
Message-ID: <5E197F1B-BDDF-40AF-9D87-D6792CE1A3B9@ya.ru> (raw)
Hi all.
There are two common practice to drop partition from partitioned table: just drop or detach-drop. But simple drop don't work if exist foreign key. Example script attached.
$ psql -p 5416 -a -f test.sql
\setenv PSQL_EDITOR 'vim'
\setenv PSQL_EDITOR_LINENUMBER_ARG '+'
\set ON_ERROR_ROLLBACK 'interactive'
\set ON_ERROR_STOP 'on'
--\set SHOW_CONTEXT 'always'
\set PROMPT1 '%[%033[38;5;'`echo $PROMPT_COLOR`'m%]%x%n@%m:%>/%/\n%R%# %[%033[m%]'
\set PROMPT2 '%[%033[38;5;'`echo $PROMPT_COLOR`'m%]%R%# %[%033[m%]'
BEGIN;
BEGIN
CREATE TABLE parent (
id int primary key
) PARTITION BY RANGE (id);
CREATE TABLE
CREATE TABLE parent_0 PARTITION OF parent
FOR VALUES FROM (0) TO (100);
CREATE TABLE
CREATE TABLE children (
id int primary key references parent(id)
) PARTITION BY RANGE (id);
CREATE TABLE
CREATE TABLE children_0 PARTITION OF children
FOR VALUES FROM (0) TO (100);
CREATE TABLE
DROP TABLE children_0;
DROP TABLE
DROP TABLE parent_0;
psql:test.sql:15: ERROR: cannot drop table parent_0 because other objects depend on it
DETAIL: constraint children_id_fkey on table children depends on table parent_0
HINT: Use DROP ... CASCADE to drop the dependent objects too.
Looked like a bug.=
Attachments:
test.sql (application/octet-stream, 373B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: splarv@ya.ru
Subject: Re: Can not drop partition if exist foreign keys
In-Reply-To: <5E197F1B-BDDF-40AF-9D87-D6792CE1A3B9@ya.ru>
References: <5E197F1B-BDDF-40AF-9D87-D6792CE1A3B9@ya.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox