Add FAQ entry to mention using COALESCE() for concatenation of possible
authorBruce Momjian
Mon, 11 Dec 2006 22:44:53 +0000 (22:44 +0000)
committerBruce Momjian
Mon, 11 Dec 2006 22:44:53 +0000 (22:44 +0000)
NULLs.

doc/FAQ
doc/src/FAQ/FAQ.html

diff --git a/doc/FAQ b/doc/FAQ
index 69351486443ee3529fc204d2f25173d4ba7b275e..2939d754411f8bd50b185ed583b4925a933721e7 100644 (file)
--- a/doc/FAQ
+++ b/doc/FAQ
@@ -1,7 +1,7 @@
 
                 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 ([email protected])
    
@@ -59,8 +59,9 @@
    4.8) How do I perform regular expression searches and case-insensitive
    regular expression searches? How do I use an index for
    case-insensitive searches?
-   4.9) In a query, how do I detect if a field is NULL? 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 do I
+   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.11.1) How do I create a serial/auto-incrementing field?
    4.11.2) How do I get the value of a SERIAL insert?
    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
    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
-  whether a field is NULL or not?
+  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?
   
    You test the column with IS NULL and IS NOT NULL, like this:
    SELECT *
    FROM tab
    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
    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
index ca960bb888ffa41485881219da0cc27e20357704..2a259db3d05fba1eb907998f317c97fbcbb6ae55 100644 (file)
@@ -10,7 +10,7 @@
   alink="#0000ff">
     

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 (

@@ -86,8 +86,8 @@
     searches and case-insensitive regular expression searches? How do I
     use an index for case-insensitive searches?
      4.9) In a query, how do I detect if a field
-    is NULL?  How can I sort on whether a field is 
-    NULL or not?
+    is NULL?  How do I 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.11.1) How do I create a
@@ -823,10 +823,14 @@ table?unlimited
     identical values that differ only in case. To force a particular
     case to be stored in the 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 whether a field is 
-    NULL or not?
+    is NULL?  How do I concatenate 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:

@@ -837,6 +841,13 @@ table?unlimited
    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 in your ORDER BY clause.
    Things that are true will sort higher than things that are false,