Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W6K1s-0004qB-QT for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Jan 2014 13:09:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W6K1s-0008Nt-6q for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Jan 2014 13:09:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W6JyA-0008JJ-Bd for pgsql-bugs@postgresql.org; Thu, 23 Jan 2014 13:05:18 +0000 Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W6Jy3-0002G9-DV for pgsql-bugs@postgresql.org; Thu, 23 Jan 2014 13:05:18 +0000 Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by depesz.com with esmtpa (Exim 4.82) (envelope-from ) id 1W6Jy0-0004Mx-2b; Thu, 23 Jan 2014 14:05:08 +0100 Date: Thu, 23 Jan 2014 14:05:08 +0100 From: hubert depesz lubaczewski To: Elyor Latipov Cc: "pgsql-bugs@postgresql.org" Subject: Re: If operator statements Message-ID: <20140123130507.GB14861@depesz.com> Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="s2ZSL+KKDSLx8OML" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --s2ZSL+KKDSLx8OML Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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/ --s2ZSL+KKDSLx8OML Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- iQIcBAEBCgAGBQJS4RODAAoJEH8YKMd1okYDy9EQALjmoDtExnzYwZ49+1kszPtE 6xfjYi6d/soStHUvOdEOSMzmOLiz/jIqFZSEpwPvpDYGiDlJHyyjqwNHkzZhO7dL Hya0PbRhGee4LwOMnF4lkFVw3HGaxM7h0wj4glnZW/M+aJwiBv4NZrLSN+zm7blj cFoLesCCCPcQGJZE56EB68/3l68vnKWoUwx32IV9mnYhtTLt3oJMl/kO8Bs2T1aR 6cL910a/OUEP62WcnhpWv/vFl+1gUvcbD21eFPN87B64i2SQ+k1LptedREHOEcDh pJU1pNy0yDv/zVBtrW68/HA6ynoMBC2O8TXg7Y1+gnVGiDVxT1IWFO4QDRmqzlCX 50LdJGs9i97eqXJ7qeLeKveeKpYze5CaEpOODauo7DPtNHrdsgyiFFLwkQgeofnM Sst0eKkx3Tp8n8UbsIoX/DS4/fVBZVlkhkwgLCv87FsJaSNN5l5E7vqIFraJVfMc 0ytc7978+UKkF7lJb0NHIVMCkNObLAiOgR49ahOjkzzhW3POsBwEqpVbrhDSM2Ul H7lFfMeUfvdvfPLponG5EXMUFDUfz18zndHIDHw0LbvsUm/WAatYyxntUwpF7KQi qXnLZ4tkkJvD+2fzn5K4YGn1VUPYJcyyWndbs9+BgH5d2jA7uCZyl20xz8JReiN1 cI7q7v/O3eX070VmQpDE =N9zN -----END PGP SIGNATURE----- --s2ZSL+KKDSLx8OML--