pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feednumbered table?
4+ messages / 3 participants
[nested] [flat]
* numbered table?
@ 1999-12-10 06:34 UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
1999-12-10 10:23 ` Re: [SQL] numbered table? UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
0 siblings, 1 reply; 4+ messages in thread
From: UEBAYASHI 'UMA' Masao @ 1999-12-10 06:34 UTC (permalink / raw)
To: pgsql-sql@hub.org
I want to create a table looks like:
num|code
---+----
1| 2
2| 3
3| 5
4| 9
from
code
----
2
3
5
9
Actually, original (code) table is not ordered, but ``SELECT DISTINCT
...'' does good work for me. I wonder if SQL has iterator or thing
like that.
Masao
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] numbered table?
1999-12-10 06:34 numbered table? UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
@ 1999-12-10 10:23 ` UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
1999-12-15 07:43 ` Re: [SQL] numbered table? UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp>
0 siblings, 1 reply; 4+ messages in thread
From: UEBAYASHI 'UMA' Masao @ 1999-12-10 10:23 UTC (permalink / raw)
To: pgsql-sql@hub.org
I've found a topic near my question, ranking, in ``SQL FOR
SMARTIES''. Thanks.
Masao
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] numbered table?
1999-12-10 06:34 numbered table? UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
1999-12-10 10:23 ` Re: [SQL] numbered table? UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
@ 1999-12-15 07:43 ` UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp>
1999-12-15 16:28 ` Re: [SQL] numbered table? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: UEBAYASHI Masao @ 1999-12-15 07:43 UTC (permalink / raw)
To: pgsql-sql@hub.org
> I've found a topic near my question, ranking, in ``SQL FOR
> SMARTIES''. Thanks.
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.
Masao
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] numbered table?
1999-12-10 06:34 numbered table? UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
1999-12-10 10:23 ` Re: [SQL] numbered table? UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
1999-12-15 07:43 ` Re: [SQL] numbered table? UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp>
@ 1999-12-15 16:28 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 1999-12-15 16:28 UTC (permalink / raw)
To: UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp>; +Cc: pgsql-sql@hub.org
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
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1999-12-15 16:28 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-12-10 06:34 numbered table? UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
1999-12-10 10:23 ` UEBAYASHI 'UMA' Masao <masao@nf.enveng.titech.ac.jp>
1999-12-15 07:43 ` UEBAYASHI Masao <masao@nf.enveng.titech.ac.jp>
1999-12-15 16:28 ` Tom Lane <tgl@sss.pgh.pa.us>
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