Server IP : 103.119.228.120 / Your IP : 3.147.6.176 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/share/doc/postgresql-9.2.24/html/ |
Upload File : |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Array 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 9.2.24 Documentation" HREF="index.html"><LINK REL="UP" TITLE="Functions and Operators" HREF="functions.html"><LINK REL="PREVIOUS" TITLE="Conditional Expressions" HREF="functions-conditional.html"><LINK REL="NEXT" TITLE="Range Functions and Operators" HREF="functions-range.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="2017-11-06T22:43:11"></HEAD ><BODY CLASS="SECT1" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" ><A HREF="index.html" >PostgreSQL 9.2.24 Documentation</A ></TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A TITLE="Conditional Expressions" HREF="functions-conditional.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="functions.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" >Chapter 9. Functions and Operators</TD ><TD WIDTH="20%" ALIGN="right" VALIGN="top" ><A TITLE="Range Functions and Operators" HREF="functions-range.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="FUNCTIONS-ARRAY" >9.18. Array Functions and Operators</A ></H1 ><P > <A HREF="functions-array.html#ARRAY-OPERATORS-TABLE" >Table 9-42</A > shows the operators available for array types. </P ><DIV CLASS="TABLE" ><A NAME="ARRAY-OPERATORS-TABLE" ></A ><P ><B >Table 9-42. Array Operators</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><COL><THEAD ><TR ><TH >Operator</TH ><TH >Description</TH ><TH >Example</TH ><TH >Result</TH ></TR ></THEAD ><TBODY ><TR ><TD > <TT CLASS="LITERAL" >=</TT > </TD ><TD >equal</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1.1,2.1,3.1]::int[] = ARRAY[1,2,3]</TT ></TD ><TD ><TT CLASS="LITERAL" >t</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" ><></TT > </TD ><TD >not equal</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1,2,3] <> ARRAY[1,2,4]</TT ></TD ><TD ><TT CLASS="LITERAL" >t</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" ><</TT > </TD ><TD >less than</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1,2,3] < ARRAY[1,2,4]</TT ></TD ><TD ><TT CLASS="LITERAL" >t</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" >></TT > </TD ><TD >greater than</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1,4,3] > ARRAY[1,2,4]</TT ></TD ><TD ><TT CLASS="LITERAL" >t</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" ><=</TT > </TD ><TD >less than or equal</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1,2,3] <= ARRAY[1,2,3]</TT ></TD ><TD ><TT CLASS="LITERAL" >t</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" >>=</TT > </TD ><TD >greater than or equal</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1,4,3] >= ARRAY[1,4,3]</TT ></TD ><TD ><TT CLASS="LITERAL" >t</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" >@></TT > </TD ><TD >contains</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1,4,3] @> ARRAY[3,1]</TT ></TD ><TD ><TT CLASS="LITERAL" >t</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" ><@</TT > </TD ><TD >is contained by</TD ><TD ><TT CLASS="LITERAL" >ARRAY[2,7] <@ ARRAY[1,7,4,2,6]</TT ></TD ><TD ><TT CLASS="LITERAL" >t</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" >&&</TT > </TD ><TD >overlap (have elements in common)</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1,4,3] && ARRAY[2,1]</TT ></TD ><TD ><TT CLASS="LITERAL" >t</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" >||</TT > </TD ><TD >array-to-array concatenation</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1,2,3] || ARRAY[4,5,6]</TT ></TD ><TD ><TT CLASS="LITERAL" >{1,2,3,4,5,6}</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" >||</TT > </TD ><TD >array-to-array concatenation</TD ><TD ><TT CLASS="LITERAL" >ARRAY[1,2,3] || ARRAY[[4,5,6],[7,8,9]]</TT ></TD ><TD ><TT CLASS="LITERAL" >{{1,2,3},{4,5,6},{7,8,9}}</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" >||</TT > </TD ><TD >element-to-array concatenation</TD ><TD ><TT CLASS="LITERAL" >3 || ARRAY[4,5,6]</TT ></TD ><TD ><TT CLASS="LITERAL" >{3,4,5,6}</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" >||</TT > </TD ><TD >array-to-element concatenation</TD ><TD ><TT CLASS="LITERAL" >ARRAY[4,5,6] || 7</TT ></TD ><TD ><TT CLASS="LITERAL" >{4,5,6,7}</TT ></TD ></TR ></TBODY ></TABLE ></DIV ><P > Array comparisons compare the array contents element-by-element, using the default B-tree comparison function for the element data type. In multidimensional arrays the elements are visited in row-major order (last subscript varies most rapidly). If the contents of two arrays are equal but the dimensionality is different, the first difference in the dimensionality information determines the sort order. (This is a change from versions of <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > prior to 8.2: older versions would claim that two arrays with the same contents were equal, even if the number of dimensions or subscript ranges were different.) </P ><P > See <A HREF="arrays.html" >Section 8.15</A > for more details about array operator behavior. </P ><P > <A HREF="functions-array.html#ARRAY-FUNCTIONS-TABLE" >Table 9-43</A > shows the functions available for use with array types. See <A HREF="arrays.html" >Section 8.15</A > for more information and examples of the use of these functions. </P ><DIV CLASS="TABLE" ><A NAME="ARRAY-FUNCTIONS-TABLE" ></A ><P ><B >Table 9-43. Array Functions</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><COL><COL><THEAD ><TR ><TH >Function</TH ><TH >Return Type</TH ><TH >Description</TH ><TH >Example</TH ><TH >Result</TH ></TR ></THEAD ><TBODY ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_append</CODE >(<TT CLASS="TYPE" >anyarray</TT >, <TT CLASS="TYPE" >anyelement</TT >) </TT > </TD ><TD ><TT CLASS="TYPE" >anyarray</TT ></TD ><TD >append an element to the end of an array</TD ><TD ><TT CLASS="LITERAL" >array_append(ARRAY[1,2], 3)</TT ></TD ><TD ><TT CLASS="LITERAL" >{1,2,3}</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_cat</CODE >(<TT CLASS="TYPE" >anyarray</TT >, <TT CLASS="TYPE" >anyarray</TT >) </TT > </TD ><TD ><TT CLASS="TYPE" >anyarray</TT ></TD ><TD >concatenate two arrays</TD ><TD ><TT CLASS="LITERAL" >array_cat(ARRAY[1,2,3], ARRAY[4,5])</TT ></TD ><TD ><TT CLASS="LITERAL" >{1,2,3,4,5}</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_ndims</CODE >(<TT CLASS="TYPE" >anyarray</TT >) </TT > </TD ><TD ><TT CLASS="TYPE" >int</TT ></TD ><TD >returns the number of dimensions of the array</TD ><TD ><TT CLASS="LITERAL" >array_ndims(ARRAY[[1,2,3], [4,5,6]])</TT ></TD ><TD ><TT CLASS="LITERAL" >2</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_dims</CODE >(<TT CLASS="TYPE" >anyarray</TT >) </TT > </TD ><TD ><TT CLASS="TYPE" >text</TT ></TD ><TD >returns a text representation of array's dimensions</TD ><TD ><TT CLASS="LITERAL" >array_dims(ARRAY[[1,2,3], [4,5,6]])</TT ></TD ><TD ><TT CLASS="LITERAL" >[1:2][1:3]</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_fill</CODE >(<TT CLASS="TYPE" >anyelement</TT >, <TT CLASS="TYPE" >int[]</TT >, [<SPAN CLASS="OPTIONAL" >, <TT CLASS="TYPE" >int[]</TT ></SPAN >]) </TT > </TD ><TD ><TT CLASS="TYPE" >anyarray</TT ></TD ><TD >returns an array initialized with supplied value and dimensions, optionally with lower bounds other than 1</TD ><TD ><TT CLASS="LITERAL" >array_fill(7, ARRAY[3], ARRAY[2])</TT ></TD ><TD ><TT CLASS="LITERAL" >[2:4]={7,7,7}</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_length</CODE >(<TT CLASS="TYPE" >anyarray</TT >, <TT CLASS="TYPE" >int</TT >) </TT > </TD ><TD ><TT CLASS="TYPE" >int</TT ></TD ><TD >returns the length of the requested array dimension</TD ><TD ><TT CLASS="LITERAL" >array_length(array[1,2,3], 1)</TT ></TD ><TD ><TT CLASS="LITERAL" >3</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_lower</CODE >(<TT CLASS="TYPE" >anyarray</TT >, <TT CLASS="TYPE" >int</TT >) </TT > </TD ><TD ><TT CLASS="TYPE" >int</TT ></TD ><TD >returns lower bound of the requested array dimension</TD ><TD ><TT CLASS="LITERAL" >array_lower('[0:2]={1,2,3}'::int[], 1)</TT ></TD ><TD ><TT CLASS="LITERAL" >0</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_prepend</CODE >(<TT CLASS="TYPE" >anyelement</TT >, <TT CLASS="TYPE" >anyarray</TT >) </TT > </TD ><TD ><TT CLASS="TYPE" >anyarray</TT ></TD ><TD >append an element to the beginning of an array</TD ><TD ><TT CLASS="LITERAL" >array_prepend(1, ARRAY[2,3])</TT ></TD ><TD ><TT CLASS="LITERAL" >{1,2,3}</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_to_string</CODE >(<TT CLASS="TYPE" >anyarray</TT >, <TT CLASS="TYPE" >text</TT > [<SPAN CLASS="OPTIONAL" >, <TT CLASS="TYPE" >text</TT ></SPAN >]) </TT > </TD ><TD ><TT CLASS="TYPE" >text</TT ></TD ><TD >concatenates array elements using supplied delimiter and optional null string</TD ><TD ><TT CLASS="LITERAL" >array_to_string(ARRAY[1, 2, 3, NULL, 5], ',', '*')</TT ></TD ><TD ><TT CLASS="LITERAL" >1,2,3,*,5</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >array_upper</CODE >(<TT CLASS="TYPE" >anyarray</TT >, <TT CLASS="TYPE" >int</TT >) </TT > </TD ><TD ><TT CLASS="TYPE" >int</TT ></TD ><TD >returns upper bound of the requested array dimension</TD ><TD ><TT CLASS="LITERAL" >array_upper(ARRAY[1,8,3,7], 1)</TT ></TD ><TD ><TT CLASS="LITERAL" >4</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >string_to_array</CODE >(<TT CLASS="TYPE" >text</TT >, <TT CLASS="TYPE" >text</TT > [<SPAN CLASS="OPTIONAL" >, <TT CLASS="TYPE" >text</TT ></SPAN >]) </TT > </TD ><TD ><TT CLASS="TYPE" >text[]</TT ></TD ><TD >splits string into array elements using supplied delimiter and optional null string</TD ><TD ><TT CLASS="LITERAL" >string_to_array('xx~^~yy~^~zz', '~^~', 'yy')</TT ></TD ><TD ><TT CLASS="LITERAL" >{xx,NULL,zz}</TT ></TD ></TR ><TR ><TD > <TT CLASS="LITERAL" > <CODE CLASS="FUNCTION" >unnest</CODE >(<TT CLASS="TYPE" >anyarray</TT >) </TT > </TD ><TD ><TT CLASS="TYPE" >setof anyelement</TT ></TD ><TD >expand an array to a set of rows</TD ><TD ><TT CLASS="LITERAL" >unnest(ARRAY[1,2])</TT ></TD ><TD ><PRE CLASS="LITERALLAYOUT" >1 2</PRE >(2 rows)</TD ></TR ></TBODY ></TABLE ></DIV ><P > In <CODE CLASS="FUNCTION" >string_to_array</CODE >, if the delimiter parameter is NULL, each character in the input string will become a separate element in the resulting array. If the delimiter is an empty string, then the entire input string is returned as a one-element array. Otherwise the input string is split at each occurrence of the delimiter string. </P ><P > In <CODE CLASS="FUNCTION" >string_to_array</CODE >, if the null-string parameter is omitted or NULL, none of the substrings of the input will be replaced by NULL. In <CODE CLASS="FUNCTION" >array_to_string</CODE >, if the null-string parameter is omitted or NULL, any null elements in the array are simply skipped and not represented in the output string. </P ><DIV CLASS="NOTE" ><BLOCKQUOTE CLASS="NOTE" ><P ><B >Note: </B > There are two differences in the behavior of <CODE CLASS="FUNCTION" >string_to_array</CODE > from pre-9.1 versions of <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >. First, it will return an empty (zero-element) array rather than NULL when the input string is of zero length. Second, if the delimiter string is NULL, the function splits the input into individual characters, rather than returning NULL as before. </P ></BLOCKQUOTE ></DIV ><P > See also <A HREF="functions-aggregate.html" >Section 9.20</A > about the aggregate function <CODE CLASS="FUNCTION" >array_agg</CODE > for use with arrays. </P ></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="functions-conditional.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-range.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Conditional Expressions</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="functions.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Range Functions and Operators</TD ></TR ></TABLE ></DIV ></BODY ></HTML >