Re: making queries more effecient - Mailing list pgsql-sql

From Josh Berkus
Subject Re: making queries more effecient
Date
Msg-id 200211011409.01771.josh@agliodbs.com
Whole thread Raw
In response to making queries more effecient  ("Peter T. Brown" <peter@memeticsystems.com>)
List pgsql-sql
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
ORDERBY "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 BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: Kevin Old
Date:
Subject: Subtracting time fields
Next
From: Robert Treat
Date:
Subject: Re: HA PostgreSQL