Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a2b498c

Browse files
committed
Add info about selecting a random row.
1 parent a6f01d1 commit a2b498c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

doc/FAQ

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Frequently Asked Questions (FAQ) for PostgreSQL
33

4-
Last updated: Mon May 26 15:25:04 EDT 2003
4+
Last updated: Wed May 28 00:35:16 EDT 2003
55

66
Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
77

@@ -58,7 +58,7 @@
5858
Operational Questions
5959

6060
4.1) What is the difference between binary cursors and normal cursors?
61-
4.2) How do I SELECT only the first few rows of a query?
61+
4.2) How do I SELECT only the first few rows of a query? A random row?
6262
4.3) How do I get a list of tables or other things I can see in psql?
6363
4.4) How do you remove a column from a table, or change it's data
6464
type?
@@ -627,7 +627,7 @@
627627

628628
See the DECLARE manual page for a description.
629629

630-
4.2) How do I SELECT only the first few rows of a query?
630+
4.2) How do I SELECT only the first few rows of a query? A random row?
631631

632632
See the FETCH manual page, or use SELECT ... LIMIT....
633633

@@ -637,6 +637,12 @@
637637
evaluate only the first few records requested, or the entire query may
638638
have to be evaluated until the desired rows have been generated.
639639

640+
To SELECT a random row, use:
641+
SELECT col
642+
FROM tab
643+
ORDER BY random()
644+
LIMIT 1;
645+
640646
4.3) How do I get a list of tables or other things I can see in psql?
641647

642648
You can read the source code for psql in file

doc/src/FAQ/FAQ.html

+11-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
alink="#0000ff">
1111
<H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
1212

13-
<P>Last updated: Mon May 26 15:25:04 EDT 2003</P>
13+
<P>Last updated: Wed May 28 00:35:16 EDT 2003</P>
1414

1515
<P>Current maintainer: Bruce Momjian (<A href=
1616
"mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR>
@@ -83,7 +83,7 @@ <H2 align="center">Operational Questions</H2>
8383
<A href="#4.1">4.1</A>) What is the difference between binary
8484
cursors and normal cursors?<BR>
8585
<A href="#4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
86-
first few rows of a query?<BR>
86+
first few rows of a query? A random row?<BR>
8787
<A href="#4.3">4.3</A>) How do I get a list of tables or other
8888
things I can see in <I>psql</I>?<BR>
8989
<A href="#4.4">4.4</A>) How do you remove a column from a
@@ -799,7 +799,7 @@ <H4><A name="4.1">4.1</A>) What is the difference between binary
799799
description.</P>
800800

801801
<H4><A name="4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
802-
first few rows of a query?</H4>
802+
first few rows of a query? A random row?</H4>
803803

804804
<P>See the <SMALL>FETCH</SMALL> manual page, or use
805805
<SMALL>SELECT</SMALL> ... <SMALL>LIMIT</SMALL>....</P>
@@ -811,6 +811,14 @@ <H4><A name="4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
811811
records requested, or the entire query may have to be evaluated
812812
until the desired rows have been generated.</P>
813813

814+
<P>To <SMALL>SELECT</SMALL> a random row, use:
815+
<PRE>
816+
SELECT col
817+
FROM tab
818+
ORDER BY random()
819+
LIMIT 1;
820+
</PRE>
821+
814822
<H4><A name="4.3">4.3</A>) How do I get a list of tables or other
815823
things I can see in <I>psql</I>?</H4>
816824

0 commit comments

Comments
 (0)