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

SQL state 42601 FOR syntax error

From: "Ramroth, Laurie" <Laurie(dot)Ramroth(at)nrel(dot)gov>
To: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: SQL state 42601 FOR syntax error
Date: 2010-12-22 22:57:14
Message-ID: 9700A92FD044934E8E64B214D8B0F38C1C1B0BDA55@MAILBOX1.nrel.gov (view raw or flat)
Thread:
Lists: pgsql-novice
Sir/Madam:

The code that follows iterates on a temporary table of distinct vehicle id's that results from a query on the normal.joined_points_speeds_orderedID table.  The normal.joined_points_speeds_orderedid table has vehicle_id, trip_id, local_ts, calc_miles_duration, calc_time_duration, and calc_speed fields and is ordered by vehicle_id. The purpose of this code is to break up a large table of point level vehicle data by vehicle_id (into several smaller tables stored as csv).  I think the code that follows should do this by copying temporary tables into csv files, however it doesn't.  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 ...

********Error**********
ERROR: syntax error at or near "FOR"
SQL state: 42601
Character: 1

Can you spot the error in the included code?

Thank you.

Laurie Ramroth


Responses

pgsql-novice by date

Next:From: Mladen GogalaDate: 2010-12-22 22:57:54
Subject: Does Skype outage have anything to do with PostgreSQL?
Previous:From: Tom LaneDate: 2010-12-22 15:12:31
Subject: Re: pg_largeobject and toast

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