Thread: If operator statements

If operator statements

From
Elyor Latipov
Date:
Don't work this statement:

IF NOT EXISTS (select TRUE from information_schema.constraint_column_usage =
where constraint_name=3D'projects_pkey')=20
THEN
    ALTER TABLE projects ADD CONSTRAINT projects_pkey PRIMARY KEY(id)=3B
END IF=3B =20


__________________
Best regards=2C
Elyor.
                           =

Re: If operator statements

From
hubert depesz lubaczewski
Date:
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/