Re: making queries more effecient

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: "Peter T(dot) Brown" <peter(at)memeticsystems(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: making queries more effecient
Date: 2002-11-01 22:09:01
Message-ID: 200211011409.01771.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Robert Treat 2002-11-01 22:12:50 Re: HA PostgreSQL
Previous Message Kevin Old 2002-11-01 22:05:26 Subtracting time fields