Skip site navigation (1) Skip section navigation (2)

Re: SQL state 42601 FOR syntax error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ramroth, Laurie" <Laurie(dot)Ramroth(at)nrel(dot)gov>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: SQL state 42601 FOR syntax error
Date: 2010-12-23 03:05:42
Message-ID: 14344.1293073542@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
"Ramroth, Laurie" <Laurie(dot)Ramroth(at)nrel(dot)gov> writes:
> I get a FOR syntax error on the following code.

> FOR rowNum IN SELECT DISTINCT ON (vehicle_id) vehicle_id FROM normal.joined_points_speeds_orderedID LOOP
>     EXECUTE 'CREATE  TEMP TABLE vehiclePointData_'||rowNum|| 'AS SELECT * FROM normal.joined_points_speeds_orderedID WHERE joined_points_speeds_orderedID.vehicle_id='||rowNum;
>    EXECUTE 'COPY vehiclePointData_'||rowNum||'TO D:/PSRC_Public_access/calculations_points_speeds/'||rowNum||'.csv delimiters '||','||' WITH CSV HEADER';
> END LOOP;

> The Error reads-
> ERROR:  syntax error at or near "FOR"
> LINE 1: FOR rowNum IN (SELECT DISTINCT ON (vehicle_id) vehicle_id ...

You haven't provided us a lot of context, but I'm going to guess that
you are trying to execute this as just plain SQL.  It's not SQL.
FOR is a construct in the plpgsql procedural language; so you need to
put this into a plpgsql function.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Mladen GogalaDate: 2010-12-23 13:42:40
Subject: Re: Does Skype outage have anything to do with PostgreSQL?
Previous:From: Shoaib MirDate: 2010-12-23 00:56:05
Subject: Re: Does Skype outage have anything to do with PostgreSQL?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group