Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd979f6

Browse files
committed
Redesign DISTINCT ON as discussed in pgsql-sql 1/25/00: syntax is now
SELECT DISTINCT ON (expr [, expr ...]) targetlist ...and there is a check to make sure that the user didn't specify an ORDER BYthat's incompatible with the DISTINCT operation.Reimplement nodeUnique and nodeGroup to use the proper datatype-specificequality function for each column being compared --- they used to dobitwise comparisons or convert the data to text strings and strcmp().(To add insult to injury, they'd look up the conversion functions oncefor each tuple...) Parse/plan representation of DISTINCT is now a listof SortClause nodes.initdb forced by querytree change...
1 parent3f0074e commitdd979f6

32 files changed

+607
-545
lines changed

‎doc/src/sgml/ref/select.sgml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.23 1999/12/13 17:39:38 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.24 2000/01/27 18:11:25 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -22,7 +22,7 @@ Postgres documentation
2222
<date>1999-07-20</date>
2323
</refsynopsisdivinfo>
2424
<synopsis>
25-
SELECT [ ALL | DISTINCT [ ON <replaceable class="PARAMETER">column</replaceable> ] ]
25+
SELECT [ ALL | DISTINCT [ ON(<replaceable class="PARAMETER">expression</replaceable> [, ...] ) ] ]
2626
<replaceable class="PARAMETER">expression</replaceable> [ AS <replaceable class="PARAMETER">name</replaceable> ] [, ...]
2727
[ INTO [ TEMPORARY | TEMP ] [ TABLE ] <replaceable class="PARAMETER">new_table</replaceable> ]
2828
[ FROM <replaceable class="PARAMETER">table</replaceable> [ <replaceable class="PARAMETER">alias</replaceable> ] [, ...] ]
@@ -201,16 +201,29 @@ SELECT [ ALL | DISTINCT [ ON <replaceable class="PARAMETER">column</replaceable>
201201
</para>
202202

203203
<para>
204-
<command>DISTINCT</command> will eliminateallduplicate rows from the
204+
<command>DISTINCT</command> will eliminate duplicate rows from the
205205
result.
206-
<command>DISTINCT ON <replaceable class="PARAMETER">column</replaceable></command>
207-
will eliminate all duplicates in the specified column; this is
208-
similar to using
209-
<command>GROUP BY <replaceable class="PARAMETER">column</replaceable></command>.
210-
<command>ALL</command> will return all candidate rows,
206+
<command>ALL</command> (the default) will return all candidate rows,
211207
including duplicates.
212208
</para>
213209

210+
<para>
211+
<command>DISTINCT ON</command> eliminates rows that match on all the
212+
specified expressions, keeping only the first row of each set of
213+
duplicates. Note that "the first row" of each set is unpredictable
214+
unless <command>ORDER BY</command> is used to ensure that the desired
215+
row appears first. For example,
216+
<programlisting>
217+
SELECT DISTINCT ON (location) location, time, report
218+
FROM weatherReports
219+
ORDER BY location, time DESC;
220+
</programlisting>
221+
retrieves the most recent weather report for each location. But if
222+
we had not used ORDER BY to force descending order of time values
223+
for each location, we'd have gotten a report of unpredictable age
224+
for each location.
225+
</para>
226+
214227
<para>
215228
The GROUP BY clause allows a user to divide a table
216229
conceptually into groups.

‎src/backend/executor/execTuples.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.35 2000/01/26 05:56:22 momjian Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.36 2000/01/27 18:11:27 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -753,7 +753,7 @@ NodeGetResultTupleSlot(Plan *node)
753753
{
754754
UniqueState*uniquestate= ((Unique*)node)->uniquestate;
755755

756-
slot=uniquestate->cs_ResultTupleSlot;
756+
slot=uniquestate->cstate.cs_ResultTupleSlot;
757757
}
758758
break;
759759

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp