Michael Glaesemann <grzm@xxxxxxxxxxxxx> writes: > I'm not familiar with the syntax you're using, but one problem is > that your parentheses are not balanced -- there's an extra closing > parenthesis. That's probably what the error is complaining about. You > might want to try to use whitespace to see the structure of your > query better, e.g., Also, consider using a newer Postgres release. 8.0 and up provide a cursor pointer so that you don't have to count characters: regression=# SELECT o.orgunitname AS ouname, e.entrynumber AS value_field, centroid(c.the_geom) AS the_geom, c.ogc_fid AS ogc_fid FROM (ctrphc AS c INNER JOIN orgunit o ON c.dhs_ouname = o.orgunitname) INNER JOIN (SELECT orgunitid, entrynumber FROM routinedataou4 WHERE dataelementid=1195 AND dataperiodid = 86) AS e ON o.orgunitid = e.orgunitid) AS new_table USING UNIQUE ogc_fid USING SRID=-1; ERROR: syntax error at or near ")" at character 333 LINE 1: ...taperiodid = 86) AS e ON o.orgunitid = e.orgunitid) AS new_t... ^ regression=# regards, tom lane