X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 3C2A69FA218 for ; Thu, 18 May 2006 06:19:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 90111-07 for ; Thu, 18 May 2006 06:19:45 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wx-out-0102.google.com (wx-out-0102.google.com [66.249.82.207]) by postgresql.org (Postfix) with ESMTP id 0706A9FA226 for ; Thu, 18 May 2006 06:19:45 -0300 (ADT) Received: by wx-out-0102.google.com with SMTP id h29so64643wxd for ; Thu, 18 May 2006 02:19:44 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=K0LeXWoGQ9kE2t+Wft5Zg9bNso5/F2rFoyWa//dG+5r5MqnH492OP+QNn1eIw0kqLyKd7lybM9/Kvja48cH9heXE2Zxl2QJRDX1VAwDY73O8R+WULNZmMGBjq01mufveFixsbr7vUKH12w5kCA05YSG1524MXL7Uo99AY5V43YE= Received: by 10.70.76.17 with SMTP id y17mr401377wxa; Thu, 18 May 2006 02:19:44 -0700 (PDT) Received: by 10.70.110.20 with HTTP; Thu, 18 May 2006 02:19:44 -0700 (PDT) Message-ID: Date: Thu, 18 May 2006 05:19:44 -0400 From: "Michael Artz" To: jaychiu@ureach.com Subject: Re: Question about SQL Control Structure(if then, for loop) Cc: pgsql-sql@postgresql.org In-Reply-To: <200605170151.VAA30155@www20.ureach.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_33622_7860965.1147943984038" References: <200605170151.VAA30155@www20.ureach.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/134 X-Sequence-Number: 25165 ------=_Part_33622_7860965.1147943984038 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline If you're control is that simple, you can write similar statements in pure SQL: RDM=3D# for i in 1 .. 10 loop > RDM-# select "test" > RDM-# end loop; > ERROR: syntax error at or near "for" at character 1 > LINE 1: for i in 1 .. 10 loop SELECT 'test' FROM RDM=3D# if exits ( select * from testtable) > RDM-# then > RDM-# select "TEST" > RDM-# ; > ERROR: syntax error at or near "if" at character 1 > LINE 1: if exits ( select * from testtable) > ^ SELECT 'test' FROM testtable LIMIT 1; Without knowing about what you want to do, I can't guarantee that that will suffice and/or be efficient. If it gets much more complicated, you might have to go to some procedural language (PL/PGSQL, PL/Perl, etc). Just remember that SQL is set-based, not procedural. -Mike ------=_Part_33622_7860965.1147943984038 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline

If you're control is that simple, you can write similar state= ments in pure SQL:

RDM=3D# for i in 1 .. 10 loop
RDM-# select "test"
RDM-# end= loop;
ERROR:  syntax error at or near "for" at char= acter 1
LINE 1: for i in 1 .. 10 loop

SELECT 'test' FROM


RDM= =3D# if exits ( select * from testtable)
RDM-# then
RDM-# select &quo= t;TEST"
RDM-# ;
ERROR:  syntax error at or near "if" at = character 1
LINE 1: if exits ( select * from testtable)
  &= nbsp;     ^

 SELECT 'tes= t' FROM testtable LIMIT 1;

Without knowing about what yo= u want to do, I can't guarantee that that will suffice and/or be efficient.=   If it gets much more complicated, you might have to go to some proce= dural language (PL/PGSQL, PL/Perl, etc).  Just remember that SQL is se= t-based, not procedural.

-Mike ------=_Part_33622_7860965.1147943984038--