Re: Dynamic constraint names in ALTER TABLE - Mailing list pgsql-general

From patrick keshishian
Subject Re: Dynamic constraint names in ALTER TABLE
Date
Msg-id CAN0yQBoJfUH2c=hNQoojMFtEH-=6NAe-J7sFwwf9smNg50POtw@mail.gmail.com
Whole thread Raw
In response to Re: Dynamic constraint names in ALTER TABLE  (Ondrej Ivanič <ondrej.ivanic@gmail.com>)
List pgsql-general
2011/9/19 Ondrej Ivanič <ondrej.ivanic@gmail.com>:
> Hi,
>
> On 20 September 2011 13:09, patrick keshishian <pkeshish@gmail.com> wrote:
>> e.g., ALTER TABLE sales DROP CONSTRAINT (SELECT conname FROM
>> pg_constraint JOIN pg_class ON (conrelid=pg_class.oid) WHERE
>> pg_class.relname='sales' AND conkey[1] = 1 AND contype='f') ;
>
> You have to build query in different way:
>
> psql ... -A -t -c "SELECT 'ALTER TABLE sales DROP CONSTRAINT ' ||
> conname || ';' FROM pg_constraint JOIN pg_class ON
> (conrelid=pg_class.oid) WHERE pg_class.relname='sales' AND conkey[1] =
> 1 AND contype='f'"
>
> Finally, you can save it in to file or pipe it to another psql:
> psql ... -A -t -c '....' | psql ...

this is no different than my save to a file (\o) and read it back (\i) way.

--patrick

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Dynamic constraint names in ALTER TABLE
Next
From: patrick keshishian
Date:
Subject: Re: Dynamic constraint names in ALTER TABLE