Re: SQL state 42601 FOR syntax error - Mailing list pgsql-novice

From Tom Lane
Subject Re: SQL state 42601 FOR syntax error
Date
Msg-id 14344.1293073542@sss.pgh.pa.us
Whole thread Raw
In response to SQL state 42601 FOR syntax error  ("Ramroth, Laurie" <Laurie.Ramroth@nrel.gov>)
List pgsql-novice
"Ramroth, Laurie" <Laurie.Ramroth@nrel.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
WHEREjoined_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

pgsql-novice by date:

Previous
From: Shoaib Mir
Date:
Subject: Re: Does Skype outage have anything to do with PostgreSQL?
Next
From: Mladen Gogala
Date:
Subject: Re: Does Skype outage have anything to do with PostgreSQL?