Re: clone_schema function

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Igor Neyman <ineyman(at)perceptron(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: clone_schema function
Date: 2015-09-11 14:22:12
Message-ID: CANu8FiyJtt-0q=bkUxyra66tHi6FFzgU8TqVR2aahseCBDDntA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Here is one more tweak of clone_schema.

I've added an include_recs flag.
If FALSE, then no records are copied into the tables from the old_schema
and all sequences start with the minimum value.
If TRUE, then all records are copied and sequences are set tot the last
value.

On Thu, Sep 10, 2015 at 11:52 AM, Melvin Davidson <melvin6925(at)gmail(dot)com>
wrote:

> Yes, however, the documentation would be a lot clearer if it said "copies
> all constraints except foreign keys". I've made this known.
>
> At any rate, I've attached a new version of the function that now does
> copy the foreign keys. Let me know if I missed anything else.
>
> On Thu, Sep 10, 2015 at 9:09 AM, Igor Neyman <ineyman(at)perceptron(dot)com>
> wrote:
>
>>
>>
>>
>>
>> *From:* Melvin Davidson [mailto:melvin6925(at)gmail(dot)com]
>> *Sent:* Wednesday, September 09, 2015 4:48 PM
>> *To:* Igor Neyman <ineyman(at)perceptron(dot)com>
>> *Cc:* pgsql-general(at)postgresql(dot)org
>> *Subject:* Re: [GENERAL] clone_schema function
>>
>>
>>
>> Thanks Igor,
>>
>> hmm, apparently the "INCLUDING CONSTRAINTS' option of "CREATE TABLE' has
>> a glitch and only includes the primary key.
>>
>> I also noticed that INCLUDING ALL generates an error, so I'll have to
>> report that also.
>>
>> I'll go eat some crow and work on a fix to add all constraints in the
>> meantime.
>>
>>
>>
>>
>>
>> It’s not a bug.
>>
>> According to docs:
>>
>> “Not-null constraints are always copied to the new table. CHECK
>> constraints will only be copied if INCLUDING CONSTRAINTS is specified;
>> other types of constraints will never be copied.”
>>
>> So, FK constraints are not supposed to be copied.
>>
>>
>>
>> Regards,
>>
>> Igor Neyman
>>
>
>
>
> --
> *Melvin Davidson*
> I reserve the right to fantasize. Whether or not you
> wish to share my fantasy is entirely up to you.
>

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

Attachment Content-Type Size
clone_schema.sql application/octet-stream 5.6 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2015-09-11 16:30:03 Re: clone_schema function
Previous Message David G. Johnston 2015-09-11 12:17:42 Re: Domains, check_violation and undefined column field in error