Re: Question about SQL Control Structure(if then, for loop) - Mailing list pgsql-sql

From Michael Artz
Subject Re: Question about SQL Control Structure(if then, for loop)
Date
Msg-id e9c163070605180219n4d78faa1r22992bb622a56892@mail.gmail.com
Whole thread Raw
In response to Question about SQL Control Structure(if then, for loop)  (Jay Chiu <jaychiu@ureach.com>)
Responses Re: Question about SQL Control Structure(if then, for loop)
List pgsql-sql

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

pgsql-sql by date:

Previous
From: "Dirk Jagdmann"
Date:
Subject: Re: table constraint + INSERT
Next
From: "Michael Artz"
Date:
Subject: Re: Question about SQL Control Structure(if then, for loop)