Re: If operator statements - Mailing list pgsql-bugs

From hubert depesz lubaczewski
Subject Re: If operator statements
Date
Msg-id 20140123130507.GB14861@depesz.com
Whole thread Raw
In response to If operator statements  (Elyor Latipov <elyor@outlook.com>)
List pgsql-bugs
On Thu, Jan 23, 2014 at 12:50:09PM +0500, Elyor Latipov wrote:
> Don't work this statement:
> IF NOT EXISTS (select TRUE from information_schema.constraint_column_usag=
e where constraint_name=3D'projects_pkey')=20
> THEN
>     ALTER TABLE projects ADD CONSTRAINT projects_pkey PRIMARY KEY(id);
> END IF; =20

If you're running it as SQL command (for example in psql session) - it
will not work, as SQL doesn't have "IF" command.
IF is a command in PL/pgSQL, but to use it you have to either make
a function, or use:
DO $$....$$;
sql command.

Best regards,

depesz

--=20
The best thing about modern society is how easy it is to avoid contact with=
 it.
                                                             http://depesz.=
com/

pgsql-bugs by date:

Previous
From: deadhead
Date:
Subject: Re: BUG #8869: ip4r93-1.05-3.rhel6 syntax error in ip4r.sql - LANGUAGE 'C' instead of LANGUAGE 'c'
Next
From: Marti Raudsepp
Date:
Subject: Re: BUG #8929: Drupal Website not working on Postgres 9.2