pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stuart <sfbarbee@gmail.com>
To: pgsql-bugs@postgresql.org
Subject: Errors creating partitioned tables from existing using (LIKE <table>) after renaming table constraints
Date: Wed, 12 Dec 2018 23:00:22 +0300
Message-ID: <2047094.V130LYfLq4@station53.ousa.org> (raw)

Dear team,

I am using PostGreSQL 11.1, I compiled from source on openSuSE Tumbleweed.
ousa_new=# SELECT version() ;                                                          version ---------------------------------------------------------------------------------------------------------------------------- PostgreSQL 11.1 on x86_64-pc-linux-gnu, compiled by gcc (SUSE Linux) 8.2.1 20181025 [gcc-8-branch revision 265488], 64-bit

I imported a table definition from another database using:

pg_dump -d ousa -t knowledge_vectors -s | psql ousa_new

The table inherits from a hierarchy and I imported those parent tables first.  I want to test partitioning so in the new db, I renamed the table and all its indexes and constraints so I can create a new table partitioned table based on this design using (like <table>).

ousa_new=# \d+ knowledge_vectors_old
                                                    Table "public.knowledge_vectors_old"
    Column     |            Type             | Collation | Nullable |            Default             | Storage  | Stats target | Description
---------------+-----------------------------+-----------+----------+--------------------------------+----------+--------------+-------------
 entry_date    | timestamp(3) with time zone |           | not null | now()                          | plain    |              |
 revision_date | timestamp(3) with time zone |           |          | NULL::timestamp with time zone | plain    |              |
 entered_by    | text                        |           | not null | "current_user"()               | extended |              |
 revised_by    | text                        |           |          | ''::text                       | extended |              |
 source_id     | bigint                      |           |          |                                | plain    |              |
 object_id     | bigint                      |           | not null |                                | plain    |              |
 description   | text                        |           |          | ''::text                       | extended |              |
 vectors       | tsvector                    |           | not null |                                | extended |              |
Indexes:
    "knowledgevectorsold_pk" PRIMARY KEY, btree (object_id), tablespace "pgindex"
    "knowledgevectorsold_vector_idx" gin (vectors), tablespace "pgindex"
Check constraints:
    "knowledgevectors_vectors_ck" CHECK (vectors <> ''::tsvector)
Foreign-key constraints:
    "knowledgevectorsold_objectid_fk" FOREIGN KEY (object_id) REFERENCES knowledge(object_id)
Triggers:
    knowledgevectors_revision_tr BEFORE UPDATE ON knowledge_vectors_old FOR EACH ROW EXECUTE PROCEDURE revised()
Inherits: ousa_objects


ousa_new=# alter table knowledge_vectors_old rename constraint knowledgevectors_vectors_ck to knowledgevectorsold_vectors_ck ;
ALTER TABLE

ousa_new=# \d+ knowledge_vectors_old
                                                    Table "public.knowledge_vectors_old"
    Column     |            Type             | Collation | Nullable |            Default             | Storage  | Stats target | Description
---------------+-----------------------------+-----------+----------+--------------------------------+----------+--------------+-------------
 entry_date    | timestamp(3) with time zone |           | not null | now()                          | plain    |              |
 revision_date | timestamp(3) with time zone |           |          | NULL::timestamp with time zone | plain    |              |
 entered_by    | text                        |           | not null | "current_user"()               | extended |              |
 revised_by    | text                        |           |          | ''::text                       | extended |              |
 source_id     | bigint                      |           |          |                                | plain    |              |
 object_id     | bigint                      |           | not null |                                | plain    |              |
 description   | text                        |           |          | ''::text                       | extended |              |
 vectors       | tsvector                    |           | not null |                                | extended |              |
Indexes:
    "knowledgevectorsold_pk" PRIMARY KEY, btree (object_id), tablespace "pgindex"
    "knowledgevectorsold_vector_idx" gin (vectors), tablespace "pgindex"
Check constraints:
    "knowledgevectorsold_vectors_ck" CHECK (vectors <> ''::tsvector)
Foreign-key constraints:
    "knowledgevectorsold_objectid_fk" FOREIGN KEY (object_id) REFERENCES knowledge(object_id)
Triggers:
    knowledgevectors_revision_tr BEFORE UPDATE ON knowledge_vectors_old FOR EACH ROW EXECUTE PROCEDURE revised()
Inherits: ousa_objects

On my attempt to create the new partitioned table using like, I get error that the constraint by the old name doesn't exist:

ousa_new=# create table knowledge_vectors (like knowledge_vectors_old INCLUDING ALL ) PARTITION BY RANGE ( object_id ) ;
ERROR:  constraint "knowledgevectors_vectors_ck" for table "knowledge_vectors_old" does not exist

Only after I dropped the new constraint and recreated it, did the create table (like <table>) work.

Ousa_new=# alter table knowledge_vectors_old drop constraint knowledgevectorsold_vectors_ck ;
ALTER TABLE

ousa_new=# alter table knowledge_vectors_old add constraint knowledgevectorsold_vectors_ck CHECK (vectors <> ''::tsvector) ;
ALTER TABLE

ousa_new=# \d+ knowledge_vectors_old
                                                    Table "public.knowledge_vectors_old"
    Column     |            Type             | Collation | Nullable |            Default             | Storage  | Stats target | Description
---------------+-----------------------------+-----------+----------+--------------------------------+----------+--------------+-------------
 entry_date    | timestamp(3) with time zone |           | not null | now()                          | plain    |              |
 revision_date | timestamp(3) with time zone |           |          | NULL::timestamp with time zone | plain    |              |
 entered_by    | text                        |           | not null | "current_user"()               | extended |              |
 revised_by    | text                        |           |          | ''::text                       | extended |              |
 source_id     | bigint                      |           |          |                                | plain    |              |
 object_id     | bigint                      |           | not null |                                | plain    |              |
 description   | text                        |           |          | ''::text                       | extended |              |
 vectors       | tsvector                    |           | not null |                                | extended |              |
Indexes:
    "knowledgevectorsold_pk" PRIMARY KEY, btree (object_id), tablespace "pgindex"
    "knowledgevectorsold_vector_idx" gin (vectors), tablespace "pgindex"
Check constraints:
    "knowledgevectorsold_vectors_ck" CHECK (vectors <> ''::tsvector)
Foreign-key constraints:
    "knowledgevectorsold_objectid_fk" FOREIGN KEY (object_id) REFERENCES knowledge(object_id)
Triggers:
    knowledgevectors_revision_tr BEFORE UPDATE ON knowledge_vectors_old FOR EACH ROW EXECUTE PROCEDURE revised()
Inherits: ousa_objects


ousa_new=# create table knowledge_vectors (like knowledge_vectors_old INCLUDING ALL ) PARTITION BY RANGE ( object_id ) ;
CREATE TABLE

ousa_new=# \d+ knowledge_vectors
                                                      Table "public.knowledge_vectors"
    Column     |            Type             | Collation | Nullable |            Default             | Storage  | Stats target | Description
---------------+-----------------------------+-----------+----------+--------------------------------+----------+--------------+-------------
 entry_date    | timestamp(3) with time zone |           | not null | now()                          | plain    |              |
 revision_date | timestamp(3) with time zone |           |          | NULL::timestamp with time zone | plain    |              |
 entered_by    | text                        |           | not null | "current_user"()               | extended |              |
 revised_by    | text                        |           |          | ''::text                       | extended |              |
 source_id     | bigint                      |           |          |                                | plain    |              |
 object_id     | bigint                      |           | not null |                                | plain    |              |
 description   | text                        |           |          | ''::text                       | extended |              |
 vectors       | tsvector                    |           | not null |                                | extended |              |
Partition key: RANGE (object_id)
Indexes:
    "knowledge_vectors_pkey" PRIMARY KEY, btree (object_id), tablespace "pgindex"
    "knowledge_vectors_vectors_idx" gin (vectors), tablespace "pgindex"
Check constraints:
    "knowledgevectorsold_vectors_ck" CHECK (vectors <> ''::tsvector)
Number of partitions: 0


The original table is:

ousa# \d+ knowledge_vectors
                                                      Table "public.knowledge_vectors"
    Column     |            Type             | Collation | Nullable |            Default             | Storage  | Stats target | Description
---------------+-----------------------------+-----------+----------+--------------------------------+----------+--------------+-------------
 entry_date    | timestamp(3) with time zone |           | not null | now()                          | plain    |              |
 revision_date | timestamp(3) with time zone |           |          | NULL::timestamp with time zone | plain    |              |
 entered_by    | text                        |           | not null | "current_user"()               | extended |              |
 revised_by    | text                        |           |          | ''::text                       | extended |              |
 source_id     | bigint                      |           |          |                                | plain    |              |
 object_id     | bigint                      |           | not null |                                | plain    |              |
 description   | text                        |           |          | ''::text                       | extended |              |
 vectors       | tsvector                    |           | not null |                                | extended |              |
Indexes:
    "knowledgevectors_pk" PRIMARY KEY, btree (object_id), tablespace "pgindex"
    "knowledgevectors_vector_idx" gin (vectors), tablespace "pgindex"
Check constraints:
    "knowledgevectors_vectors_ck" CHECK (vectors <> ''::tsvector)
Triggers:
    knowledgevectors_revision_tr BEFORE UPDATE ON knowledge_vectors FOR EACH ROW EXECUTE PROCEDURE revised()
Inherits: ousa_objects

view thread (12+ messages)  latest in thread

Message-ID: <2047094.V130LYfLq4@station53.ousa.org>
Permalink:  ../2047094.V130LYfLq4@station53.ousa.org/
Also on:    postgresql.org/message-id/2047094.V130LYfLq4@station53.ousa.org

 · 

reply

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-bugs@postgresql.org
  Cc: sfbarbee@gmail.com
  Subject: Re: Errors creating partitioned tables from existing using (LIKE <table>) after renaming table constraints
  In-Reply-To: <2047094.V130LYfLq4@station53.ousa.org>
  References: <2047094.V130LYfLq4@station53.ousa.org>

* 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