|
1 |
| -<!-- $Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.42 2000/12/16 18:33:13 tgl Exp $ --> |
| 1 | +<!-- $Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.43 2000/12/16 19:33:23 tgl Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="functions">
|
4 | 4 | <title>Functions and Operators</title>
|
|
805 | 805 |
|
806 | 806 | <para>
|
807 | 807 | If <replaceable>pattern</replaceable> does not contain percent
|
808 |
| - signs or underscore then the pattern only represents the string |
| 808 | + signs or underscore, then the pattern only represents the string |
809 | 809 | itself; in that case <function>LIKE</function> acts like the
|
810 | 810 | equals operator. An underscore (<literal>_</literal>) in
|
811 | 811 | <replaceable>pattern</replaceable> stands for (matches) any single
|
812 |
| - character, a percent sign (<literal>%</literal>) matches zero or |
813 |
| - more characters. |
| 812 | + character; a percent sign (<literal>%</literal>) matches any string |
| 813 | + of zero or more characters. |
814 | 814 | </para>
|
815 | 815 |
|
816 | 816 | <informalexample>
|
|
827 | 827 |
|
828 | 828 | <para>
|
829 | 829 | <function>LIKE</function> pattern matches always cover the entire
|
830 |
| - string. On order to match a pattern anywhere within a string, the |
| 830 | + string. To match a pattern anywhere within a string, the |
831 | 831 | pattern must therefore start and end with a percent sign.
|
832 | 832 | </para>
|
833 | 833 |
|
834 | 834 | <para>
|
835 |
| - In order to match a literal underscore or percent sign, the |
836 |
| - respective character in <replaceable>pattern</replaceable> must be |
837 |
| - preceded by the active escape character. The default escape |
| 835 | + To match a literal underscore or percent sign without matching |
| 836 | + other characters, the respective character in |
| 837 | + <replaceable>pattern</replaceable> must be |
| 838 | + preceded by the escape character. The default escape |
838 | 839 | character is the backslash but a different one may be selected by
|
839 |
| - using the <literal>ESCAPE</literal> clause. When using the |
840 |
| - backslash as escape character in literal strings it must be |
841 |
| - doubled, because the backslash already has a special meaning in |
842 |
| - string literals. |
| 840 | + using the <literal>ESCAPE</literal> clause. To match the escape |
| 841 | + character itself, write two escape characters. |
| 842 | + </para> |
| 843 | + |
| 844 | + <para> |
| 845 | + Note that the backslash already has a special meaning in string |
| 846 | + literals, so to write a pattern constant that contains a backslash |
| 847 | + you must write two backslashes in the query. You can avoid this by |
| 848 | + selecting a different escape character with <literal>ESCAPE</literal>. |
843 | 849 | </para>
|
844 | 850 |
|
845 | 851 | <para>
|
846 | 852 | The keyword <token>ILIKE</token> can be used instead of
|
847 | 853 | <token>LIKE</token> to make the match case insensitive according
|
848 |
| - to the active locale. This is a |
| 854 | + to the active locale. This is not in the SQL standard but is a |
849 | 855 | <productname>Postgres</productname> extension.
|
850 | 856 | </para>
|
851 | 857 |
|
852 | 858 | <para>
|
853 | 859 | The operator <literal>~~</literal> is equivalent to
|
854 |
| - <function>LIKE</function>, <literal>~~*</literal> corresponds to |
855 |
| - <literal>ILIKE</literal>. Finally, there are also |
856 |
| - <literal>!~~</literal> and <literal>!~~*</literal> operators to |
| 860 | + <function>LIKE</function>, and <literal>~~*</literal> corresponds to |
| 861 | + <function>ILIKE</function>. There are also |
| 862 | + <literal>!~~</literal> and <literal>!~~*</literal> operators that |
857 | 863 | represent <function>NOT LIKE</function> and <function>NOT
|
858 | 864 | ILIKE</function>. All of these are also
|
859 | 865 | <productname>Postgres</productname>-specific.
|
|
864 | 870 | <sect2 id="functions-regexp">
|
865 | 871 | <title>POSIX Regular Expressions</title>
|
866 | 872 |
|
867 |
| - <para> |
868 |
| - POSIX regular expressions provide a more powerful means for |
869 |
| - pattern matching than the <function>LIKE</function> function. |
870 |
| - Many Unix tools such as <command>egrep</command>, |
871 |
| - <command>sed</command>, or <command>awk</command> use a pattern |
872 |
| - matching language that is similar to the one described here. |
873 |
| - </para> |
874 |
| - |
875 |
| - <para> |
876 |
| - A regular expression is a character sequence that is an |
877 |
| - abbreviated definition of a set of strings (a <firstterm>regular |
878 |
| - set</firstterm>). A string is said to match a regular expression |
879 |
| - if it is a member of the regular set described by the regular |
880 |
| - expression. Unlike the <function>LIKE</function> operator, a |
881 |
| - regular expression also matches anywhere within a string, unless |
882 |
| - the regular expression is explicitly anchored to the beginning or |
883 |
| - end of the string. |
884 |
| - </para> |
885 |
| - |
886 | 873 | <table>
|
887 | 874 | <title>Regular Expression Match Operators</title>
|
888 | 875 |
|
|
920 | 907 | </tgroup>
|
921 | 908 | </table>
|
922 | 909 |
|
| 910 | + <para> |
| 911 | + POSIX regular expressions provide a more powerful means for |
| 912 | + pattern matching than the <function>LIKE</function> function. |
| 913 | + Many Unix tools such as <command>egrep</command>, |
| 914 | + <command>sed</command>, or <command>awk</command> use a pattern |
| 915 | + matching language that is similar to the one described here. |
| 916 | + </para> |
| 917 | + |
| 918 | + <para> |
| 919 | + A regular expression is a character sequence that is an |
| 920 | + abbreviated definition of a set of strings (a <firstterm>regular |
| 921 | + set</firstterm>). A string is said to match a regular expression |
| 922 | + if it is a member of the regular set described by the regular |
| 923 | + expression. As with <function>LIKE</function>, pattern characters |
| 924 | + match string characters exactly unless they are special characters |
| 925 | + in the regular expression language --- but regular expressions use |
| 926 | + different special characters than <function>LIKE</function> does. |
| 927 | + Unlike <function>LIKE</function> patterns, a |
| 928 | + regular expression is allowed to match anywhere within a string, unless |
| 929 | + the regular expression is explicitly anchored to the beginning or |
| 930 | + end of the string. |
| 931 | + </para> |
| 932 | + |
923 | 933 |
|
924 | 934 | <!-- derived from the re_format.7 man page -->
|
925 | 935 | <para>
|
926 | 936 | Regular expressions (<quote>RE</quote>s), as defined in POSIX
|
927 | 937 | 1003.2, come in two forms: modern REs (roughly those of
|
928 | 938 | <command>egrep</command>; 1003.2 calls these
|
929 | 939 | <quote>extended</quote> REs) and obsolete REs (roughly those of
|
930 |
| - <command>ed</command>; 1003.2 <quote>basic</quote> REs). Obsolete |
931 |
| - REs are not available in <productname>Postgres</productname>. |
| 940 | + <command>ed</command>; 1003.2 <quote>basic</quote> REs). |
| 941 | + <productname>Postgres</productname> implements the modern form. |
932 | 942 | </para>
|
933 | 943 |
|
934 | 944 | <para>
|
|
1004 | 1014 | <literal>\</literal>.
|
1005 | 1015 | </para>
|
1006 | 1016 |
|
| 1017 | + <para> |
| 1018 | + Note that the backslash (<literal>\</literal>) already has a special |
| 1019 | + meaning in string |
| 1020 | + literals, so to write a pattern constant that contains a backslash |
| 1021 | + you must write two backslashes in the query. |
| 1022 | + </para> |
| 1023 | + |
1007 | 1024 | <para>
|
1008 | 1025 | A <firstterm>bracket expression</firstterm> is a list of
|
1009 | 1026 | characters enclosed in <literal>[]</literal>. It normally matches
|
|
0 commit comments