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 EA2799F9CEE for ; Tue, 16 May 2006 23:16:17 -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 84094-01 for ; Tue, 16 May 2006 23:16:11 -0300 (ADT) X-Greylist: delayed 00:24:23.289248 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 029759FA4F2 for ; Tue, 16 May 2006 23:16:11 -0300 (ADT) Received: from ureach.com (mail31.ureach.com [63.236.74.67]) by svr4.postgresql.org (Postfix) with ESMTP id 452AF5B070E for ; Wed, 17 May 2006 01:51:47 +0000 (GMT) Received: from www20.ureach.com (www20.ureach.com [172.16.2.48]) by ureach.com (8.12.9/8.12.9) with ESMTP id k4H1pj3h011821; Tue, 16 May 2006 21:51:45 -0400 Received: (from nobody@localhost) by www20.ureach.com (8.9.3/8.9.1) id VAA30155; Tue, 16 May 2006 21:51:45 -0400 Date: Tue, 16 May 2006 21:51:45 -0400 Message-Id: <200605170151.VAA30155@www20.ureach.com> Received: from [24.199.101.139] by www20.ureach.com via HTTP; Wed, 17 May 2006 01:51:45 GMT To: pgsql-sql@postgresql.org From: Jay Chiu Reply-To: Subject: Question about SQL Control Structure(if then, for loop) Cc: jaychiu@ureach.com Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-vsuite-type: e X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/129 X-Sequence-Number: 25160 Hello, I am new to PostgreSQL and want to use the IF-THEN; LOOP statements in my SQL command file. Thus I may use psql -f cfile to exceute. However I always got syntax error on if/for in psql. For example: 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 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) ^ Can someone tell me how to use if/for in psql? The document shows the control structures in the PL/pgSQL section. Must I use if/for inside some procedure/function? Thanks a lot. Jay ________________________________________________ Get your own "800" number Voicemail, fax, email, and a lot more http://www.ureach.com/reg/tag