Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VhQhm-0007C1-Gb for pgsql-admin@arkaria.postgresql.org; Fri, 15 Nov 2013 21:13:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VhQhl-0004TS-M8 for pgsql-admin@arkaria.postgresql.org; Fri, 15 Nov 2013 21:13:29 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VhQhW-000471-9A for pgsql-admin@postgresql.org; Fri, 15 Nov 2013 21:13:14 +0000 Received: from mail-qe0-x233.google.com ([2607:f8b0:400d:c02::233]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VhQhP-000700-Ho for pgsql-admin@postgresql.org; Fri, 15 Nov 2013 21:13:13 +0000 Received: by mail-qe0-f51.google.com with SMTP id t7so2574205qeb.24 for ; Fri, 15 Nov 2013 13:13:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=ea3UKIagNxcg0BrBTP55Qz1HF/yYX0Ts8i6F7+K6OEU=; b=eFUqUvpPP1GGOnrIqRQiiycSt+Fbrut2pgbsKT96V3nr/NSxS2N+GUjhh1H2RxKrDy opC/2KYwjPPfsRIKX495qrI/MD2MiyicWfobwQRE5ezunjA4iY7wPIDr/3skUCBPHBd8 hfEj1vn7FByi6rOk/ZZQWvXs4bEIvI14ngX+mkNqq8g1EQekeC8IxsQfQhh1Hg+tFrD2 ueDtY+nLkfntfswpHRirtmEFdvvyIB08js4C/Bma1VJXCE9Qt0brOsDo8ayCjTuI01HM hS0r3eJ6cPbsnZcjymt/jmrDF0BtrCE/yVNmdJ+cgT0CXLJZHPm46wxarVoxxlqRA75f FHeA== X-Received: by 10.224.4.2 with SMTP id 2mr13683413qap.29.1384549986710; Fri, 15 Nov 2013 13:13:06 -0800 (PST) Received: from [192.168.204.25] (173-161-251-161-Philadelphia.hfc.comcastbusiness.net. [173.161.251.161]) by mx.google.com with ESMTPSA id p17sm10698809qak.4.2013.11.15.13.13.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Nov 2013 13:13:06 -0800 (PST) Message-ID: <52868E61.1000806@gmail.com> Date: Fri, 15 Nov 2013 16:13:05 -0500 From: Elliot User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Thara Vadakkeveedu , Kevin Grittner , "pgsql-admin@postgresql.org" Subject: Re: checking if sequence exists References: <1384543840.72953.YahooMailNeo@web125002.mail.ne1.yahoo.com> <1384544163.79352.YahooMailNeo@web125002.mail.ne1.yahoo.com> <1384545985.96990.YahooMailNeo@web162906.mail.bf1.yahoo.com> <1384549763.68859.YahooMailNeo@web125005.mail.ne1.yahoo.com> In-Reply-To: <1384549763.68859.YahooMailNeo@web125005.mail.ne1.yahoo.com> Content-Type: multipart/alternative; boundary="------------030001040906000601090700" X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org This is a multi-part message in MIME format. --------------030001040906000601090700 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 2013-11-15 16:09, Thara Vadakkeveedu wrote: > "First, is this code in a plpgsql contex"? > No, that is my problem. > Does it have to be inside a Create function block or can justwrapping > the if with a BEGIN END; suffice ? > Control structures like if statements don't exist in straight sql - you need a procedural language like pl/pgsql for that. Wrapping sql statements in begin/end only affects the transactional context of the statements, it does not cause them to be interpreted as pl/pgsql. You can either create a function or you can use a "DO" block, which is sometimes what I use for deploy scripts [http://www.postgresql.org/docs/9.3/static/sql-do.html]. --------------030001040906000601090700 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
On 2013-11-15 16:09, Thara Vadakkeveedu wrote:
"First, is this code in a plpgsql contex"?
 
No, that is my problem.
 
Does it have to be inside a Create function block or can just wrapping the if  with a BEGIN END; suffice ?
 

Control structures like if statements don't exist in straight sql - you need a procedural language like pl/pgsql for that. Wrapping sql statements in begin/end only affects the transactional context of the statements, it does not cause them to be interpreted as pl/pgsql. You can either create a function or you can use a "DO" block, which is sometimes what I use for deploy scripts [http://www.postgresql.org/docs/9.3/static/sql-do.html]. --------------030001040906000601090700--