Re: Dynamic constraint names in ALTER TABLE

From: Ondrej Ivanič <ondrej(dot)ivanic(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Dynamic constraint names in ALTER TABLE
Date: 2011-09-20 03:23:01
Message-ID: CAM6mie+Q4btvshrHpARrhDnG0544jTonP11FYtyE4VRnQUaxsQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

On 20 September 2011 13:09, patrick keshishian <pkeshish(at)gmail(dot)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 ...

--
Ondrej Ivanic
(ondrej(dot)ivanic(at)gmail(dot)com)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-09-20 03:34:29 Re: Dynamic constraint names in ALTER TABLE
Previous Message patrick keshishian 2011-09-20 03:09:04 Re: Dynamic constraint names in ALTER TABLE