Re: If operator statements

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Elyor Latipov <elyor(at)outlook(dot)com>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: If operator statements
Date: 2014-01-23 13:05:08
Message-ID: 20140123130507.GB14861@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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_usage where constraint_name='projects_pkey')
> THEN
> ALTER TABLE projects ADD CONSTRAINT projects_pkey PRIMARY KEY(id);
> END IF;

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

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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Marti Raudsepp 2014-01-23 13:15:11 Re: BUG #8929: Drupal Website not working on Postgres 9.2
Previous Message marcusoverheu 2014-01-23 09:47:12 BUG #8934: value != ANY (uuid[]) AND expr does not work in all cases