pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hubert depesz lubaczewski <depesz@depesz.com>
To: Elyor Latipov <elyor@outlook.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: If operator statements
Date: Thu, 23 Jan 2014 14:05:08 +0100
Message-ID: <20140123130507.GB14861@depesz.com> (raw)
In-Reply-To: <DUB122-W17C35B35436B45184B4A1FB1A60@phx.gbl>
References: <DUB122-W17C35B35436B45184B4A1FB1A60@phx.gbl>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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/

Attachments:

  signature.asc (application/pgp-signature, 800B) download

view thread (2+ messages)

Message-ID: <20140123130507.GB14861@depesz.com>
Permalink:  ../20140123130507.GB14861@depesz.com/
Also on:    postgresql.org/message-id/20140123130507.GB14861@depesz.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: depesz@depesz.com, elyor@outlook.com
  Subject: Re: If operator statements
  In-Reply-To: <20140123130507.GB14861@depesz.com>
  References: <DUB122-W17C35B35436B45184B4A1FB1A60@phx.gbl> <20140123130507.GB14861@depesz.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox