mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Add FAQ entry to mention using COALESCE() for concatenation of possible
NULLs.
This commit is contained in:
18
doc/FAQ
18
doc/FAQ
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Frequently Asked Questions (FAQ) for PostgreSQL
|
Frequently Asked Questions (FAQ) for PostgreSQL
|
||||||
|
|
||||||
Last updated: Tue Dec 5 18:13:32 EST 2006
|
Last updated: Mon Dec 11 17:44:33 EST 2006
|
||||||
|
|
||||||
Current maintainer: Bruce Momjian (bruce@momjian.us)
|
Current maintainer: Bruce Momjian (bruce@momjian.us)
|
||||||
|
|
||||||
@ -59,8 +59,9 @@
|
|||||||
4.8) How do I perform regular expression searches and case-insensitive
|
4.8) How do I perform regular expression searches and case-insensitive
|
||||||
regular expression searches? How do I use an index for
|
regular expression searches? How do I use an index for
|
||||||
case-insensitive searches?
|
case-insensitive searches?
|
||||||
4.9) In a query, how do I detect if a field is NULL? How can I sort on
|
4.9) In a query, how do I detect if a field is NULL? How do I
|
||||||
whether a field is NULL or not?
|
concatenate possible NULLs? How can I sort on whether a field is NULL
|
||||||
|
or not?
|
||||||
4.10) What is the difference between the various character types?
|
4.10) What is the difference between the various character types?
|
||||||
4.11.1) How do I create a serial/auto-incrementing field?
|
4.11.1) How do I create a serial/auto-incrementing field?
|
||||||
4.11.2) How do I get the value of a SERIAL insert?
|
4.11.2) How do I get the value of a SERIAL insert?
|
||||||
@ -631,15 +632,22 @@
|
|||||||
upper and lowercase characters, it can not have identical values that
|
upper and lowercase characters, it can not have identical values that
|
||||||
differ only in case. To force a particular case to be stored in the
|
differ only in case. To force a particular case to be stored in the
|
||||||
column, use a CHECK constraint or a trigger.
|
column, use a CHECK constraint or a trigger.
|
||||||
|
4.9) In a query, how do I detect if a field is NULL? How do I
|
||||||
|
concatenate possible NULLs? How can I sort on whether a field is NULL
|
||||||
|
or not?
|
||||||
|
|
||||||
4.9) In a query, how do I detect if a field is NULL? How can I sort on
|
4.9) In a query, how do I detect if a field is NULL? How do I concatenate
|
||||||
whether a field is NULL or not?
|
possible NULLs? How can I sort on whether a field is NULL or not?
|
||||||
|
|
||||||
You test the column with IS NULL and IS NOT NULL, like this:
|
You test the column with IS NULL and IS NOT NULL, like this:
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM tab
|
FROM tab
|
||||||
WHERE col IS NULL;
|
WHERE col IS NULL;
|
||||||
|
|
||||||
|
To concatentate with possible NULLs, use COALESCE(), like this:
|
||||||
|
SELECT COALESCE(col1, '') || COALESCE(col2, '')
|
||||||
|
FROM tab
|
||||||
|
|
||||||
To sort by the NULL status, use the IS NULL and IS NOT NULL modifiers
|
To sort by the NULL status, use the IS NULL and IS NOT NULL modifiers
|
||||||
in your ORDER BY clause. Things that are true will sort higher than
|
in your ORDER BY clause. Things that are true will sort higher than
|
||||||
things that are false, so the following will put NULL entries at the
|
things that are false, so the following will put NULL entries at the
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
alink="#0000ff">
|
alink="#0000ff">
|
||||||
<H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
|
<H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
|
||||||
|
|
||||||
<P>Last updated: Tue Dec 5 18:13:32 EST 2006</P>
|
<P>Last updated: Mon Dec 11 17:44:33 EST 2006</P>
|
||||||
|
|
||||||
<P>Current maintainer: Bruce Momjian (<A href=
|
<P>Current maintainer: Bruce Momjian (<A href=
|
||||||
"mailto:bruce@momjian.us">bruce@momjian.us</A>)
|
"mailto:bruce@momjian.us">bruce@momjian.us</A>)
|
||||||
@ -86,8 +86,8 @@
|
|||||||
searches and case-insensitive regular expression searches? How do I
|
searches and case-insensitive regular expression searches? How do I
|
||||||
use an index for case-insensitive searches?<BR>
|
use an index for case-insensitive searches?<BR>
|
||||||
<A href="#item4.9">4.9</A>) In a query, how do I detect if a field
|
<A href="#item4.9">4.9</A>) In a query, how do I detect if a field
|
||||||
is <SMALL>NULL</SMALL>? How can I sort on whether a field is <SMALL>
|
is <SMALL>NULL</SMALL>? How do I concatenate possible <SMALL>NULL</SMALL>s?
|
||||||
NULL</SMALL> or not?<BR>
|
How can I sort on whether a field is <SMALL> NULL</SMALL> or not?<BR>
|
||||||
<A href="#item4.10">4.10</A>) What is the difference between the
|
<A href="#item4.10">4.10</A>) What is the difference between the
|
||||||
various character types?<BR>
|
various character types?<BR>
|
||||||
<A href="#item4.11.1">4.11.1</A>) How do I create a
|
<A href="#item4.11.1">4.11.1</A>) How do I create a
|
||||||
@ -824,9 +824,13 @@ table?</TD><TD>unlimited</TD></TR>
|
|||||||
case to be stored in the column, use a <SMALL>CHECK</SMALL>
|
case to be stored in the column, use a <SMALL>CHECK</SMALL>
|
||||||
constraint or a trigger.</P>
|
constraint or a trigger.</P>
|
||||||
|
|
||||||
|
<A href="#item4.9">4.9</A>) In a query, how do I detect if a field
|
||||||
|
is <SMALL>NULL</SMALL>? How do I concatenate possible <SMALL>NULL</SMALL>s?
|
||||||
|
How can I sort on whether a field is <SMALL> NULL</SMALL> or not?<BR>
|
||||||
|
|
||||||
<H3 id="item4.9">4.9) In a query, how do I detect if a field
|
<H3 id="item4.9">4.9) In a query, how do I detect if a field
|
||||||
is <SMALL>NULL</SMALL>? How can I sort on whether a field is <SMALL>
|
is <SMALL>NULL</SMALL>? How do I concatenate possible <SMALL>NULL</SMALL>s?
|
||||||
NULL</SMALL> or not?</H3>
|
How can I sort on whether a field is <SMALL> NULL</SMALL> or not?</H3>
|
||||||
|
|
||||||
<P>You test the column with <SMALL>IS NULL</SMALL> and <SMALL>IS
|
<P>You test the column with <SMALL>IS NULL</SMALL> and <SMALL>IS
|
||||||
NOT NULL</SMALL>, like this:</P>
|
NOT NULL</SMALL>, like this:</P>
|
||||||
@ -837,6 +841,13 @@ table?</TD><TD>unlimited</TD></TR>
|
|||||||
WHERE col IS NULL;
|
WHERE col IS NULL;
|
||||||
</PRE>
|
</PRE>
|
||||||
|
|
||||||
|
<P>To concatentate with possible <SMALL>NULL</SMALL>s, use <I>COALESCE()</I>,
|
||||||
|
like this:</P>
|
||||||
|
<PRE>
|
||||||
|
SELECT COALESCE(col1, '') || COALESCE(col2, '')
|
||||||
|
FROM tab
|
||||||
|
</PRE>
|
||||||
|
|
||||||
<P>To sort by the <SMALL>NULL</SMALL> status, use the <SMALL>IS NULL</SMALL>
|
<P>To sort by the <SMALL>NULL</SMALL> status, use the <SMALL>IS NULL</SMALL>
|
||||||
and <SMALL>IS NOT NULL</SMALL> modifiers in your <SMALL>ORDER BY</SMALL> clause.
|
and <SMALL>IS NOT NULL</SMALL> modifiers in your <SMALL>ORDER BY</SMALL> clause.
|
||||||
Things that are <I>true</I> will sort higher than things that are <I>false</I>,
|
Things that are <I>true</I> will sort higher than things that are <I>false</I>,
|
||||||
|
Reference in New Issue
Block a user