pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] numbered table?
Date: Wed, 15 Dec 1999 11:28:15 -0500
Message-ID: <18362.945275295@sss.pgh.pa.us> (raw)
In-Reply-To: <19991215164328A.masao@nf.enveng.titech.ac.jp>

UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp> writes:
> At last, I dumped this ranking method. Celko's suggestion was:

>   SELECT T1.attrib0, T1.attrib1,
>     (SELECT COUNT(DISTINCT attrib1)
>        FROM Table AS T2
>          WHERE (T2.attrib1 >= T1.attrib1)
>            AND (T2.attrib0 = T1.attrib0)) AS rank
>     FROM Table AS T1
>       WHERE rank <= :n;

> or

>   SELECT T1.attrib0, T1.attrib1,
>     (SELECT COUNT(attrib1)
>        FROM Table AS T2
>          WHERE (T2.attrib1 >= T1.attrib1)
>            AND (T2.attrib0 = T2.attrib0)) AS rank
>     FROM Table AS T1
>       WHERE rank <= :n;

> Unfortunately, neither don't run in PostgreSQL.

FWIW, this does work in current development sources, with the exception
of the final "WHERE rank ..." clause --- our parser doesn't think that
AS-names from the SELECT list are valid in WHERE, and after looking at
the SQL spec I have to agree with it.  So you'd need to repeat the
sub-SELECT expression in WHERE :-(.

I don't have a clever idea at the moment for rewriting the query to
avoid the 6.5.* restrictions you're running into (no COUNT DISTINCT,
no sub-SELECTs in target lists).

			regards, tom lane



view thread (4+ messages)

Message-ID: <18362.945275295@sss.pgh.pa.us>
Permalink:  ../18362.945275295@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18362.945275295@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, masao@nf.enveng.titech.ac.jp, pgsql-sql@hub.org
  Subject: Re: [SQL] numbered table?
  In-Reply-To: <18362.945275295@sss.pgh.pa.us>
  References: <19991215164328A.masao@nf.enveng.titech.ac.jp> <18362.945275295@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox