pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Artz <mlartz@gmail.com>
To: jaychiu@ureach.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Question about SQL Control Structure(if then, for loop)
Date: Thu, 18 May 2006 05:19:44 -0400
Message-ID: <e9c163070605180219n4d78faa1r22992bb622a56892@mail.gmail.com> (raw)
In-Reply-To: <200605170151.VAA30155@www20.ureach.com>
References: <200605170151.VAA30155@www20.ureach.com>

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

RDM=# 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=# 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

view thread (4+ messages)  latest in thread

Message-ID: <e9c163070605180219n4d78faa1r22992bb622a56892@mail.gmail.com>
Permalink:  ../e9c163070605180219n4d78faa1r22992bb622a56892@mail.gmail.com/
Also on:    postgresql.org/message-id/e9c163070605180219n4d78faa1r22992bb622a56892@mail.gmail.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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mlartz@gmail.com, jaychiu@ureach.com
  Subject: Re: Question about SQL Control Structure(if then, for loop)
  In-Reply-To: <e9c163070605180219n4d78faa1r22992bb622a56892@mail.gmail.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