Re: SQL state 42601 FOR syntax error
| От | Tom Lane | 
|---|---|
| Тема | Re: SQL state 42601 FOR syntax error | 
| Дата | |
| Msg-id | 14344.1293073542@sss.pgh.pa.us обсуждение исходный текст  | 
		
| Ответ на | SQL state 42601 FOR syntax error ("Ramroth, Laurie" <Laurie.Ramroth@nrel.gov>) | 
| Список | 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 по дате отправления: