Peter,

For the rest of our sakes, in the future, please format your SQL before 
posting it to request help. 

> CREATE TEMP TABLE temp20561149207391 AS SELECT DISTINCT ON ("VisitorID")
> "VisitorID","Type" FROM "ProgramEvent" WHERE "ProgramID" = 10 ORDER BY
> "VisitorID","Created" DESC;INSERT INTO "VisitorPointer839" ("VisitorID")
> SELECT temp20561149207391."VisitorID" FROM temp20561149207391  WHERE
> temp20561149207391."Type" = 0

Can be re-written as:

INSERT INTO "VisitorPointer839" ("VisitorID")
SELECT "VisitorID" FROM (
        SELECT DISTINCT ON ("VisitorID") "VisitorID","Type" 
        FROM "ProgramEvent" WHERE "ProgramID" = 10 
        ORDER BY "VisitorID","Created" DESC ) v_first
WHERE v_first."Type" = 0;

Please also keep in mind that the SELECT DISTINCT ON syntax is a 
PostgreSQL-specific extension and is not portable.

-- 
-Josh Berkus
 Aglio Database Solutions
 San Francisco


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Reply via email to