"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