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

Commita2b498c

Browse files
committed
Add info about selecting a random row.
1 parenta6f01d1 commita2b498c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

‎doc/FAQ

Lines changed: 9 additions & 3 deletions
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 May26 15:25:04 EDT 2003
4+
Last updated:Wed May28 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

Lines changed: 11 additions & 3 deletions
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 May26 15:25:04 EDT 2003</P>
13+
<P>Last updated:Wed May28 00:35:16 EDT 2003</P>
1414

1515
<P>Current maintainer: Bruce Momjian (<Ahref=
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
<Ahref="#4.1">4.1</A>) What is the difference between binary
8484
cursors and normal cursors?<BR>
8585
<Ahref="#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
<Ahref="#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
<Ahref="#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><Aname="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><Aname="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)

[8]ページ先頭

©2009-2025 Movatter.jp