|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /proc/self/root/usr/share/doc/postgresql-8.1.9/html/ |
Upload File : |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Functions and Operators</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.1.9 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="The SQL Language"
HREF="sql.html"><LINK
REL="PREVIOUS"
TITLE="Pseudo-Types"
HREF="datatype-pseudo.html"><LINK
REL="NEXT"
TITLE="Comparison Operators"
HREF="functions-comparison.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2007-04-20T04:40:08"></HEAD
><BODY
CLASS="CHAPTER"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 8.1.9 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype-pseudo.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="typeconv.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="functions-comparison.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="FUNCTIONS"
></A
>Chapter 9. Functions and Operators</H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
>9.1. <A
HREF="functions.html#FUNCTIONS-LOGICAL"
>Logical Operators</A
></DT
><DT
>9.2. <A
HREF="functions-comparison.html"
>Comparison Operators</A
></DT
><DT
>9.3. <A
HREF="functions-math.html"
>Mathematical Functions and Operators</A
></DT
><DT
>9.4. <A
HREF="functions-string.html"
>String Functions and Operators</A
></DT
><DT
>9.5. <A
HREF="functions-binarystring.html"
>Binary String Functions and Operators</A
></DT
><DT
>9.6. <A
HREF="functions-bitstring.html"
>Bit String Functions and Operators</A
></DT
><DT
>9.7. <A
HREF="functions-matching.html"
>Pattern Matching</A
></DT
><DD
><DL
><DT
>9.7.1. <A
HREF="functions-matching.html#FUNCTIONS-LIKE"
><CODE
CLASS="FUNCTION"
>LIKE</CODE
></A
></DT
><DT
>9.7.2. <A
HREF="functions-matching.html#FUNCTIONS-SIMILARTO-REGEXP"
><CODE
CLASS="FUNCTION"
>SIMILAR TO</CODE
> Regular Expressions</A
></DT
><DT
>9.7.3. <A
HREF="functions-matching.html#FUNCTIONS-POSIX-REGEXP"
><ACRONYM
CLASS="ACRONYM"
>POSIX</ACRONYM
> Regular Expressions</A
></DT
></DL
></DD
><DT
>9.8. <A
HREF="functions-formatting.html"
>Data Type Formatting Functions</A
></DT
><DT
>9.9. <A
HREF="functions-datetime.html"
>Date/Time Functions and Operators</A
></DT
><DD
><DL
><DT
>9.9.1. <A
HREF="functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT"
><CODE
CLASS="FUNCTION"
>EXTRACT</CODE
>, <CODE
CLASS="FUNCTION"
>date_part</CODE
></A
></DT
><DT
>9.9.2. <A
HREF="functions-datetime.html#FUNCTIONS-DATETIME-TRUNC"
><CODE
CLASS="FUNCTION"
>date_trunc</CODE
></A
></DT
><DT
>9.9.3. <A
HREF="functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT"
><TT
CLASS="LITERAL"
>AT TIME ZONE</TT
></A
></DT
><DT
>9.9.4. <A
HREF="functions-datetime.html#FUNCTIONS-DATETIME-CURRENT"
>Current Date/Time</A
></DT
></DL
></DD
><DT
>9.10. <A
HREF="functions-geometry.html"
>Geometric Functions and Operators</A
></DT
><DT
>9.11. <A
HREF="functions-net.html"
>Network Address Functions and Operators</A
></DT
><DT
>9.12. <A
HREF="functions-sequence.html"
>Sequence Manipulation Functions</A
></DT
><DT
>9.13. <A
HREF="functions-conditional.html"
>Conditional Expressions</A
></DT
><DD
><DL
><DT
>9.13.1. <A
HREF="functions-conditional.html#AEN12604"
><TT
CLASS="LITERAL"
>CASE</TT
></A
></DT
><DT
>9.13.2. <A
HREF="functions-conditional.html#AEN12654"
><TT
CLASS="LITERAL"
>COALESCE</TT
></A
></DT
><DT
>9.13.3. <A
HREF="functions-conditional.html#AEN12675"
><TT
CLASS="LITERAL"
>NULLIF</TT
></A
></DT
><DT
>9.13.4. <A
HREF="functions-conditional.html#AEN12695"
><TT
CLASS="LITERAL"
>GREATEST</TT
> and <TT
CLASS="LITERAL"
>LEAST</TT
></A
></DT
></DL
></DD
><DT
>9.14. <A
HREF="functions-array.html"
>Array Functions and Operators</A
></DT
><DT
>9.15. <A
HREF="functions-aggregate.html"
>Aggregate Functions</A
></DT
><DT
>9.16. <A
HREF="functions-subquery.html"
>Subquery Expressions</A
></DT
><DD
><DL
><DT
>9.16.1. <A
HREF="functions-subquery.html#AEN13162"
><TT
CLASS="LITERAL"
>EXISTS</TT
></A
></DT
><DT
>9.16.2. <A
HREF="functions-subquery.html#AEN13186"
><TT
CLASS="LITERAL"
>IN</TT
></A
></DT
><DT
>9.16.3. <A
HREF="functions-subquery.html#AEN13211"
><TT
CLASS="LITERAL"
>NOT IN</TT
></A
></DT
><DT
>9.16.4. <A
HREF="functions-subquery.html#AEN13236"
><TT
CLASS="LITERAL"
>ANY</TT
>/<TT
CLASS="LITERAL"
>SOME</TT
></A
></DT
><DT
>9.16.5. <A
HREF="functions-subquery.html#AEN13280"
><TT
CLASS="LITERAL"
>ALL</TT
></A
></DT
><DT
>9.16.6. <A
HREF="functions-subquery.html#AEN13315"
>Row-wise Comparison</A
></DT
></DL
></DD
><DT
>9.17. <A
HREF="functions-comparisons.html"
>Row and Array Comparisons</A
></DT
><DD
><DL
><DT
>9.17.1. <A
HREF="functions-comparisons.html#AEN13354"
><TT
CLASS="LITERAL"
>IN</TT
></A
></DT
><DT
>9.17.2. <A
HREF="functions-comparisons.html#AEN13370"
><TT
CLASS="LITERAL"
>NOT IN</TT
></A
></DT
><DT
>9.17.3. <A
HREF="functions-comparisons.html#AEN13392"
><TT
CLASS="LITERAL"
>ANY</TT
>/<TT
CLASS="LITERAL"
>SOME</TT
> (array)</A
></DT
><DT
>9.17.4. <A
HREF="functions-comparisons.html#AEN13411"
><TT
CLASS="LITERAL"
>ALL</TT
> (array)</A
></DT
><DT
>9.17.5. <A
HREF="functions-comparisons.html#AEN13423"
>Row-wise Comparison</A
></DT
></DL
></DD
><DT
>9.18. <A
HREF="functions-srf.html"
>Set Returning Functions</A
></DT
><DT
>9.19. <A
HREF="functions-info.html"
>System Information Functions</A
></DT
><DT
>9.20. <A
HREF="functions-admin.html"
>System Administration Functions</A
></DT
></DL
></DIV
><A
NAME="AEN6074"
></A
><A
NAME="AEN6076"
></A
><P
> <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> provides a large number of
functions and operators for the built-in data types. Users can also
define their own functions and operators, as described in
<A
HREF="server-programming.html"
>Part V</A
>. The
<SPAN
CLASS="APPLICATION"
>psql</SPAN
> commands <TT
CLASS="COMMAND"
>\df</TT
> and
<TT
CLASS="COMMAND"
>\do</TT
> can be used to show the list of all actually
available functions and operators, respectively.
</P
><P
> If you are concerned about portability then take note that most of
the functions and operators described in this chapter, with the
exception of the most trivial arithmetic and comparison operators
and some explicitly marked functions, are not specified by the
<ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> standard. Some of the extended functionality
is present in other <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> database management
systems, and in many cases this functionality is compatible and
consistent between the various implementations. This chapter is also
not exhaustive; additional functions appear in relevant sections of
the manual.
</P
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="FUNCTIONS-LOGICAL"
>9.1. Logical Operators</A
></H1
><A
NAME="AEN6089"
></A
><A
NAME="AEN6092"
></A
><P
> The usual logical operators are available:
<A
NAME="AEN6097"
></A
>
<A
NAME="AEN6099"
></A
>
<A
NAME="AEN6101"
></A
>
<A
NAME="AEN6103"
></A
>
<A
NAME="AEN6105"
></A
>
<A
NAME="AEN6107"
></A
>
<P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>AND</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>OR</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>NOT</TT
></TD
></TR
></TBODY
></TABLE
><P
></P
>
<ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> uses a three-valued Boolean logic where the null value represents
<SPAN
CLASS="QUOTE"
>"unknown"</SPAN
>. Observe the following truth tables:
<DIV
CLASS="INFORMALTABLE"
><P
></P
><A
NAME="AEN6118"
></A
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><COL><THEAD
><TR
><TH
><TT
CLASS="REPLACEABLE"
><I
>a</I
></TT
></TH
><TH
><TT
CLASS="REPLACEABLE"
><I
>b</I
></TT
></TH
><TH
><TT
CLASS="REPLACEABLE"
><I
>a</I
></TT
> AND <TT
CLASS="REPLACEABLE"
><I
>b</I
></TT
></TH
><TH
><TT
CLASS="REPLACEABLE"
><I
>a</I
></TT
> OR <TT
CLASS="REPLACEABLE"
><I
>b</I
></TT
></TH
></TR
></THEAD
><TBODY
><TR
><TD
>TRUE</TD
><TD
>TRUE</TD
><TD
>TRUE</TD
><TD
>TRUE</TD
></TR
><TR
><TD
>TRUE</TD
><TD
>FALSE</TD
><TD
>FALSE</TD
><TD
>TRUE</TD
></TR
><TR
><TD
>TRUE</TD
><TD
>NULL</TD
><TD
>NULL</TD
><TD
>TRUE</TD
></TR
><TR
><TD
>FALSE</TD
><TD
>FALSE</TD
><TD
>FALSE</TD
><TD
>FALSE</TD
></TR
><TR
><TD
>FALSE</TD
><TD
>NULL</TD
><TD
>FALSE</TD
><TD
>NULL</TD
></TR
><TR
><TD
>NULL</TD
><TD
>NULL</TD
><TD
>NULL</TD
><TD
>NULL</TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
>
<DIV
CLASS="INFORMALTABLE"
><P
></P
><A
NAME="AEN6163"
></A
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
><TT
CLASS="REPLACEABLE"
><I
>a</I
></TT
></TH
><TH
>NOT <TT
CLASS="REPLACEABLE"
><I
>a</I
></TT
></TH
></TR
></THEAD
><TBODY
><TR
><TD
>TRUE</TD
><TD
>FALSE</TD
></TR
><TR
><TD
>FALSE</TD
><TD
>TRUE</TD
></TR
><TR
><TD
>NULL</TD
><TD
>NULL</TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
>
</P
><P
> The operators <TT
CLASS="LITERAL"
>AND</TT
> and <TT
CLASS="LITERAL"
>OR</TT
> are
commutative, that is, you can switch the left and right operand
without affecting the result. But see <A
HREF="sql-expressions.html#SYNTAX-EXPRESS-EVAL"
>Section 4.2.12</A
> for more information about the
order of evaluation of subexpressions.
</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype-pseudo.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="functions-comparison.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Pseudo-Types</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="sql.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Comparison Operators</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>