-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy patharray.html
174 lines (147 loc) · 8.84 KB
/
array.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>5.15. Array Functions and Operators — Presto 0.131 Documentation</title>
<link rel="stylesheet" href="../_static/presto.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.131',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Presto 0.131 Documentation" href="../index.html" />
<link rel="up" title="5. Functions and Operators" href="../functions.html" />
<link rel="next" title="5.16. Map Functions and Operators" href="map.html" />
<link rel="prev" title="5.14. Color Functions" href="color.html" />
</head>
<body>
<div class="header">
<h1 class="heading"><a href="../index.html">
<span>Presto 0.131 Documentation</span></a></h1>
<h2 class="heading"><span>5.15. Array Functions and Operators</span></h2>
</div>
<div class="topnav">
<p class="nav">
<span class="left">
« <a href="color.html">5.14. Color Functions</a>
</span>
<span class="right">
<a href="map.html">5.16. Map Functions and Operators</a> »
</span>
</p>
</div>
<div class="content">
<div class="section" id="array-functions-and-operators">
<h1>5.15. Array Functions and Operators</h1>
<div class="section" id="subscript-operator">
<h2>Subscript Operator: []</h2>
<p>The <tt class="docutils literal"><span class="pre">[]</span></tt> operator is used to access an element of an array and is indexed starting from one:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="n">my_array</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">AS</span> <span class="n">first_element</span>
</pre></div>
</div>
</div>
<div class="section" id="concatenation-operator">
<h2>Concatenation Operator: ||</h2>
<p>The <tt class="docutils literal"><span class="pre">||</span></tt> operator is used to concatenate an array with an array or an element of the same type:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="nb">ARRAY</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">||</span> <span class="nb">ARRAY</span> <span class="p">[</span><span class="mi">2</span><span class="p">];</span> <span class="o">=></span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="k">SELECT</span> <span class="nb">ARRAY</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">||</span> <span class="mi">2</span><span class="p">;</span> <span class="o">=></span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="k">SELECT</span> <span class="mi">2</span> <span class="o">||</span> <span class="nb">ARRAY</span> <span class="p">[</span><span class="mi">1</span><span class="p">];</span> <span class="o">=></span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
</pre></div>
</div>
</div>
<div class="section" id="array-functions">
<h2>Array Functions</h2>
<dl class="function">
<dt id="array_min">
<tt class="descname">array_min</tt><big>(</big><em>x</em><big>)</big> → x</dt>
<dd><p>Returns the minimum value of input array.</p>
</dd></dl>
<dl class="function">
<dt id="array_max">
<tt class="descname">array_max</tt><big>(</big><em>x</em><big>)</big> → x</dt>
<dd><p>Returns the maximum value of input array.</p>
</dd></dl>
<dl class="function">
<dt id="element_at">
<tt class="descname">element_at</tt><big>(</big><em>array<E></em>, <em>index</em><big>)</big> → E</dt>
<dd><p>Returns element of <tt class="docutils literal"><span class="pre">array</span></tt> at given <tt class="docutils literal"><span class="pre">index</span></tt>.
If <tt class="docutils literal"><span class="pre">index</span></tt> >= 0, this function provides the same functionality as the SQL-standard subscript operator (<tt class="docutils literal"><span class="pre">[]</span></tt>).
If <tt class="docutils literal"><span class="pre">index</span></tt> < 0, <tt class="docutils literal"><span class="pre">element_at</span></tt> accesses elements from the last to the first.</p>
</dd></dl>
<dl class="function">
<dt id="array_distinct">
<tt class="descname">array_distinct</tt><big>(</big><em>x</em><big>)</big> → array</dt>
<dd><p>Remove duplicate values from the array <tt class="docutils literal"><span class="pre">x</span></tt>.</p>
</dd></dl>
<dl class="function">
<dt id="array_intersect">
<tt class="descname">array_intersect</tt><big>(</big><em>x</em>, <em>y</em><big>)</big> → array</dt>
<dd><p>Returns an array of the elements in the intersection of <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt>, without duplicates.</p>
</dd></dl>
<dl class="function">
<dt id="array_position">
<tt class="descname">array_position</tt><big>(</big><em>x</em>, <em>element</em><big>)</big> → bigint</dt>
<dd><p>Returns the position of the first occurrence of the <tt class="docutils literal"><span class="pre">element</span></tt> in array <tt class="docutils literal"><span class="pre">x</span></tt> (or 0 if not found).</p>
</dd></dl>
<dl class="function">
<dt id="array_sort">
<tt class="descname">array_sort</tt><big>(</big><em>x</em><big>)</big> → array</dt>
<dd><p>Sorts and returns the array <tt class="docutils literal"><span class="pre">x</span></tt>. The elements of <tt class="docutils literal"><span class="pre">x</span></tt> must be orderable.</p>
</dd></dl>
<dl class="function">
<dt id="cardinality">
<tt class="descname">cardinality</tt><big>(</big><em>x</em><big>)</big> → bigint</dt>
<dd><p>Returns the cardinality (size) of the array <tt class="docutils literal"><span class="pre">x</span></tt>.</p>
</dd></dl>
<dl class="function">
<dt>
<tt class="descname">concat</tt><big>(</big><em>x</em>, <em>y</em><big>)</big> → array</dt>
<dd><p>Concatenates the arrays <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt>. This function provides the same
functionality as the SQL-standard concatenation operator (<tt class="docutils literal"><span class="pre">||</span></tt>).</p>
</dd></dl>
<dl class="function">
<dt id="contains">
<tt class="descname">contains</tt><big>(</big><em>x</em>, <em>element</em><big>)</big> → boolean</dt>
<dd><p>Returns true if the array <tt class="docutils literal"><span class="pre">x</span></tt> contains the <tt class="docutils literal"><span class="pre">element</span></tt>.</p>
</dd></dl>
<dl class="function">
<dt id="array_join">
<tt class="descname">array_join</tt><big>(</big><em>x</em>, <em>delimiter</em>, <em>null_replacement</em><big>)</big> → varchar</dt>
<dd><p>Concatenates the elements of the given array using the delimiter and an optional string to replace nulls.</p>
</dd></dl>
<dl class="function">
<dt id="array_remove">
<tt class="descname">array_remove</tt><big>(</big><em>x</em>, <em>element</em><big>)</big> → array</dt>
<dd><p>Remove all elements that equal <tt class="docutils literal"><span class="pre">element</span></tt> from array <tt class="docutils literal"><span class="pre">x</span></tt>.</p>
</dd></dl>
<dl class="function">
<dt id="slice">
<tt class="descname">slice</tt><big>(</big><em>x</em>, <em>start</em>, <em>length</em><big>)</big> → array</dt>
<dd><p>Subsets array <tt class="docutils literal"><span class="pre">x</span></tt> starting from index <tt class="docutils literal"><span class="pre">start</span></tt> (or starting from the end if <tt class="docutils literal"><span class="pre">start</span></tt> is negative) with a length of <tt class="docutils literal"><span class="pre">length</span></tt>.</p>
</dd></dl>
</div>
</div>
</div>
<div class="bottomnav">
<p class="nav">
<span class="left">
« <a href="color.html">5.14. Color Functions</a>
</span>
<span class="right">
<a href="map.html">5.16. Map Functions and Operators</a> »
</span>
</p>
</div>
<div class="footer">
</div>
</body>
</html>