Datasets:
File size: 20,093 Bytes
6493056 | 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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | <!DOCTYPE html>
<html data-theme="light" lang="en"><head>
<title>PostgreSQL: Documentation: 18: VALUES</title>
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport"/>
<meta content="text/xhtml; charset=utf-8" http-equiv="Content-Type"/>
<meta content="#336791" name="theme-color"/>
<meta content="The PostgreSQL Global Development Group" name="copyright"/>
<meta content="/docs/18/sql-values.html" property="og:url"/>
<meta content="article" property="og:type"/>
<meta content="2026-02-26T14:07:09" property="article:published_time"/>
<meta content="/media/img/about/press/elephant.png" property="og:image"/>
<meta content="VALUES" property="og:title"/>
<meta content="VALUES VALUES — compute a set of rows Synopsis VALUES ( expression [, ...] ) [, ...] [ ORDER BY …" property="og:description"/>
<meta content="PostgreSQL Documentation" property="og:site_name"/>
<link href="/media/css/fontawesome.css?54a05eb2" rel="stylesheet"/>
<link href="/media/css/bootstrap-4.4.1.min.css" rel="stylesheet"/>
<link href="/favicon.ico" rel="shortcut icon"/>
<link href="/dyncss/base.css?54a05eb2" rel="stylesheet" type="text/css"/>
<script src="/media/js/theme.js?54a05eb2"></script>
<link href="/docs/current/sql-values.html" rel="canonical"/>
</head>
<body>
<div class="container-fluid">
<div class="row justify-content-md-center">
<div class="col">
<!-- Header -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand p-0" href="/">
<img alt="PostgreSQL Elephant Logo" class="logo" src="/media/img/about/press/elephant.png"/>
</a>
<input aria-controls="pgNavbar" aria-expanded="false" aria-label="Toggle navigation" id="navbar-toggler" type="checkbox"/>
<label class="navbar-toggler" for="navbar-toggler" id="navbar-toggler-label" tabindex="0"><span class="navbar-toggler-icon"></span></label>
<div class="navbar-collapse" id="pgNavbar">
<ul class="navbar-nav mr-auto">
<li class="nav-item p-2"><a href="/" title="Home">Home</a></li>
<li class="nav-item p-2"><a href="/about/" title="About">About</a></li>
<li class="nav-item p-2"><a href="/download/" title="Download">Download</a></li>
<li class="nav-item p-2"><a href="/docs/" title="Documentation">Documentation</a></li>
<li class="nav-item p-2"><a href="/community/" title="Community">Community</a></li>
<li class="nav-item p-2"><a href="/developer/" title="Developers">Developers</a></li>
<li class="nav-item p-2"><a href="/support/" title="Support">Support</a></li>
<li class="nav-item p-2"><a href="/about/donate/" title="Donate">Donate</a></li>
<li class="nav-item p-2"><a href="/account/" title="Your account">Your account</a></li>
</ul>
<form action="/search/" method="get" role="search">
<div class="input-group">
<input accesskey="s" class="form-control" id="q" maxlength="255" name="q" placeholder="Search for..." size="20" type="text"/>
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="fas fa-search"></i></button>
</span>
</div><!-- /input-group -->
</form>
<form class="form-inline" id="form-theme">
<button class="btn btn-default ml-1" id="btn-theme" type="button"><i class="fas fa-moon"></i></button>
</form>
</div>
</nav>
</div>
</div>
<div class="row justify-content-center pg-shout-box">
<div class="col text-white text-center">February 26, 2026: <a href="/about/news/postgresql-183-179-1613-1517-and-1422-released-3246/">
PostgreSQL 18.3, 17.9, 16.13, 15.17, and 14.22 Released!
</a>
</div>
</div>
</div>
<div class="container-fluid margin">
<div class="row">
<div class="col-11" id="pgContentWrap">
<div class="row">
<div class="col-md-6 mb-2">
<div class="row">
<div class="col">
<div>
<a href="/docs/" title="Documentation">Documentation</a> → <a href="/docs/18/index.html">PostgreSQL 18</a>
</div>
</div>
</div>
<div class="row">
<div class="col">
Supported Versions:
<a class="docs-version-selected" href="/docs/current/sql-values.html" title="PostgreSQL 18 - VALUES">Current</a>
(<a class="docs-version-selected" href="/docs/18/sql-values.html" title="PostgreSQL 18 - VALUES">18</a>)
/
<a href="/docs/17/sql-values.html" title="PostgreSQL 17 - VALUES">17</a>
/
<a href="/docs/16/sql-values.html" title="PostgreSQL 16 - VALUES">16</a>
/
<a href="/docs/15/sql-values.html" title="PostgreSQL 15 - VALUES">15</a>
/
<a href="/docs/14/sql-values.html" title="PostgreSQL 14 - VALUES">14</a>
</div>
</div>
<div class="row">
<div class="col">
Development Versions:
<a href="/docs/devel/sql-values.html" rel="nofollow" title="PostgreSQL devel - VALUES">devel</a>
</div>
</div>
<div class="row">
<div class="col-12">
Unsupported versions:
<a href="/docs/13/sql-values.html" rel="nofollow" title="PostgreSQL 13 - VALUES">13</a>
/
<a href="/docs/12/sql-values.html" rel="nofollow" title="PostgreSQL 12 - VALUES">12</a>
/
<a href="/docs/11/sql-values.html" rel="nofollow" title="PostgreSQL 11 - VALUES">11</a>
/
<a href="/docs/10/sql-values.html" rel="nofollow" title="PostgreSQL 10 - VALUES">10</a>
/
<a href="/docs/9.6/sql-values.html" rel="nofollow" title="PostgreSQL 9.6 - VALUES">9.6</a>
/
<a href="/docs/9.5/sql-values.html" rel="nofollow" title="PostgreSQL 9.5 - VALUES">9.5</a>
/
<a href="/docs/9.4/sql-values.html" rel="nofollow" title="PostgreSQL 9.4 - VALUES">9.4</a>
/
<a href="/docs/9.3/sql-values.html" rel="nofollow" title="PostgreSQL 9.3 - VALUES">9.3</a>
/
<a href="/docs/9.2/sql-values.html" rel="nofollow" title="PostgreSQL 9.2 - VALUES">9.2</a>
/
<a href="/docs/9.1/sql-values.html" rel="nofollow" title="PostgreSQL 9.1 - VALUES">9.1</a>
/
<a href="/docs/9.0/sql-values.html" rel="nofollow" title="PostgreSQL 9.0 - VALUES">9.0</a>
/
<a href="/docs/8.4/sql-values.html" rel="nofollow" title="PostgreSQL 8.4 - VALUES">8.4</a>
/
<a href="/docs/8.3/sql-values.html" rel="nofollow" title="PostgreSQL 8.3 - VALUES">8.3</a>
/
<a href="/docs/8.2/sql-values.html" rel="nofollow" title="PostgreSQL 8.2 - VALUES">8.2</a>
</div>
</div>
</div>
<div class="col-md-6 col-lg-5 offset-lg-1">
<form action="/search/" id="docSearchForm" method="get" role="search">
<input name="u" type="hidden" value="/docs/18/"/>
<div class="input-group">
<input class="form-control" id="q" name="q" placeholder="Search the documentation for..." type="text"/>
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="fas fa-search"></i></button>
</span>
</div><!-- /input-group -->
</form>
</div>
</div>
<div id="docContent">
<div class="navheader">
<table summary="Navigation header" width="100%">
<tbody><tr>
<th align="center" colspan="5">VALUES</th>
</tr>
<tr>
<td align="left" width="10%"><a accesskey="p" href="/docs/current/static/sql-vacuum.html" title="VACUUM">Prev</a> </td>
<td align="left" width="10%"><a accesskey="u" href="/docs/current/static/sql-commands.html" title="SQL Commands">Up</a></td>
<th align="center" width="60%">SQL Commands</th>
<td align="right" width="10%"><a accesskey="h" href="/docs/current/static/index.html" title="PostgreSQL 18.3 Documentation">Home</a></td>
<td align="right" width="10%"> <a accesskey="n" href="/docs/current/static/reference-client.html" title="PostgreSQL Client Applications">Next</a></td>
</tr>
</tbody></table>
<hr/>
</div>
<div class="refentry" id="SQL-VALUES">
<div class="titlepage"></div><a class="indexterm" id="id-1.9.3.185.1" name="id-1.9.3.185.1"></a>
<div class="refnamediv">
<h2><span class="refentrytitle">VALUES</span></h2>
<p>VALUES — compute a set of rows</p>
</div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">VALUES ( <em class="replaceable"><code>expression</code></em> [, ...] ) [, ...]
[ ORDER BY <em class="replaceable"><code>sort_expression</code></em> [ ASC | DESC | USING <em class="replaceable"><code>operator</code></em> ] [, ...] ]
[ LIMIT { <em class="replaceable"><code>count</code></em> | ALL } ]
[ OFFSET <em class="replaceable"><code>start</code></em> [ ROW | ROWS ] ]
[ FETCH { FIRST | NEXT } [ <em class="replaceable"><code>count</code></em> ] { ROW | ROWS } ONLY ]
</pre>
</div>
<div class="refsect1" id="id-1.9.3.185.5">
<h2>Description</h2>
<p><code class="command">VALUES</code> computes a row value or set of row values specified by value expressions. It is most commonly used to generate a <span class="quote">“<span class="quote">constant table</span>”</span> within a larger command, but it can be used on its own.</p>
<p>When more than one row is specified, all the rows must have the same number of elements. The data types of the resulting table's columns are determined by combining the explicit or inferred types of the expressions appearing in that column, using the same rules as for <code class="literal">UNION</code> (see <a class="xref" href="/docs/current/static/typeconv-union-case.html" title="10.5. UNION, CASE, and Related Constructs">Section 10.5</a>).</p>
<p>Within larger commands, <code class="command">VALUES</code> is syntactically allowed anywhere that <code class="command">SELECT</code> is. Because it is treated like a <code class="command">SELECT</code> by the grammar, it is possible to use the <code class="literal">ORDER BY</code>, <code class="literal">LIMIT</code> (or equivalently <code class="literal">FETCH FIRST</code>), and <code class="literal">OFFSET</code> clauses with a <code class="command">VALUES</code> command.</p>
</div>
<div class="refsect1" id="id-1.9.3.185.6">
<h2>Parameters</h2>
<div class="variablelist">
<dl class="variablelist">
<dt><span class="term"><em class="replaceable"><code>expression</code></em></span></dt>
<dd>
<p>A constant or expression to compute and insert at the indicated place in the resulting table (set of rows). In a <code class="command">VALUES</code> list appearing at the top level of an <code class="command">INSERT</code>, an <em class="replaceable"><code>expression</code></em> can be replaced by <code class="literal">DEFAULT</code> to indicate that the destination column's default value should be inserted. <code class="literal">DEFAULT</code> cannot be used when <code class="command">VALUES</code> appears in other contexts.</p>
</dd>
<dt><span class="term"><em class="replaceable"><code>sort_expression</code></em></span></dt>
<dd>
<p>An expression or integer constant indicating how to sort the result rows. This expression can refer to the columns of the <code class="command">VALUES</code> result as <code class="literal">column1</code>, <code class="literal">column2</code>, etc. For more details see <a class="xref" href="/docs/current/static/sql-select.html#SQL-ORDERBY" title="ORDER BY Clause">ORDER BY Clause</a> in the <a class="xref" href="/docs/current/static/sql-select.html" title="SELECT"><span class="refentrytitle">SELECT</span></a> documentation.</p>
</dd>
<dt><span class="term"><em class="replaceable"><code>operator</code></em></span></dt>
<dd>
<p>A sorting operator. For details see <a class="xref" href="/docs/current/static/sql-select.html#SQL-ORDERBY" title="ORDER BY Clause">ORDER BY Clause</a> in the <a class="xref" href="/docs/current/static/sql-select.html" title="SELECT"><span class="refentrytitle">SELECT</span></a> documentation.</p>
</dd>
<dt><span class="term"><em class="replaceable"><code>count</code></em></span></dt>
<dd>
<p>The maximum number of rows to return. For details see <a class="xref" href="/docs/current/static/sql-select.html#SQL-LIMIT" title="LIMIT Clause">LIMIT Clause</a> in the <a class="xref" href="/docs/current/static/sql-select.html" title="SELECT"><span class="refentrytitle">SELECT</span></a> documentation.</p>
</dd>
<dt><span class="term"><em class="replaceable"><code>start</code></em></span></dt>
<dd>
<p>The number of rows to skip before starting to return rows. For details see <a class="xref" href="/docs/current/static/sql-select.html#SQL-LIMIT" title="LIMIT Clause">LIMIT Clause</a> in the <a class="xref" href="/docs/current/static/sql-select.html" title="SELECT"><span class="refentrytitle">SELECT</span></a> documentation.</p>
</dd>
</dl>
</div>
</div>
<div class="refsect1" id="id-1.9.3.185.7">
<h2>Notes</h2>
<p><code class="command">VALUES</code> lists with very large numbers of rows should be avoided, as you might encounter out-of-memory failures or poor performance. <code class="command">VALUES</code> appearing within <code class="command">INSERT</code> is a special case (because the desired column types are known from the <code class="command">INSERT</code>'s target table, and need not be inferred by scanning the <code class="command">VALUES</code> list), so it can handle larger lists than are practical in other contexts.</p>
</div>
<div class="refsect1" id="id-1.9.3.185.8">
<h2>Examples</h2>
<p>A bare <code class="command">VALUES</code> command:</p>
<pre class="programlisting">VALUES (1, 'one'), (2, 'two'), (3, 'three');
</pre>
<p>This will return a table of two columns and three rows. It's effectively equivalent to:</p>
<pre class="programlisting">SELECT 1 AS column1, 'one' AS column2
UNION ALL
SELECT 2, 'two'
UNION ALL
SELECT 3, 'three';
</pre>
<p>More usually, <code class="command">VALUES</code> is used within a larger SQL command. The most common use is in <code class="command">INSERT</code>:</p>
<pre class="programlisting">INSERT INTO films (code, title, did, date_prod, kind)
VALUES ('T_601', 'Yojimbo', 106, '1961-06-16', 'Drama');
</pre>
<p>In the context of <code class="command">INSERT</code>, entries of a <code class="command">VALUES</code> list can be <code class="literal">DEFAULT</code> to indicate that the column default should be used here instead of specifying a value:</p>
<pre class="programlisting">INSERT INTO films VALUES
('UA502', 'Bananas', 105, DEFAULT, 'Comedy', '82 minutes'),
('T_601', 'Yojimbo', 106, DEFAULT, 'Drama', DEFAULT);
</pre>
<p><code class="command">VALUES</code> can also be used where a sub-<code class="command">SELECT</code> might be written, for example in a <code class="literal">FROM</code> clause:</p>
<pre class="programlisting">SELECT f.*
FROM films f, (VALUES('MGM', 'Horror'), ('UA', 'Sci-Fi')) AS t (studio, kind)
WHERE f.studio = t.studio AND f.kind = t.kind;
UPDATE employees SET salary = salary * v.increase
FROM (VALUES(1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase)
WHERE employees.depno = v.depno AND employees.sales >= v.target;
</pre>
<p>Note that an <code class="literal">AS</code> clause is required when <code class="command">VALUES</code> is used in a <code class="literal">FROM</code> clause, just as is true for <code class="command">SELECT</code>. It is not required that the <code class="literal">AS</code> clause specify names for all the columns, but it's good practice to do so. (The default column names for <code class="command">VALUES</code> are <code class="literal">column1</code>, <code class="literal">column2</code>, etc. in <span class="productname">PostgreSQL</span>, but these names might be different in other database systems.)</p>
<p>When <code class="command">VALUES</code> is used in <code class="command">INSERT</code>, the values are all automatically coerced to the data type of the corresponding destination column. When it's used in other contexts, it might be necessary to specify the correct data type. If the entries are all quoted literal constants, coercing the first is sufficient to determine the assumed type for all:</p>
<pre class="programlisting">SELECT * FROM machines
WHERE ip_address IN (VALUES('192.168.0.1'::inet), ('192.168.0.10'), ('192.168.1.43'));
</pre>
<div class="tip">
<h3 class="title">Tip</h3>
<p>For simple <code class="literal">IN</code> tests, it's better to rely on the <a class="link" href="/docs/current/static/functions-comparisons.html#FUNCTIONS-COMPARISONS-IN-SCALAR" title="9.25.1. IN">list-of-scalars</a> form of <code class="literal">IN</code> than to write a <code class="command">VALUES</code> query as shown above. The list of scalars method requires less writing and is often more efficient.</p>
</div>
</div>
<div class="refsect1" id="id-1.9.3.185.9">
<h2>Compatibility</h2>
<p><code class="command">VALUES</code> conforms to the SQL standard. <code class="literal">LIMIT</code> and <code class="literal">OFFSET</code> are <span class="productname">PostgreSQL</span> extensions; see also under <a class="xref" href="/docs/current/static/sql-select.html" title="SELECT"><span class="refentrytitle">SELECT</span></a>.</p>
</div>
<div class="refsect1" id="id-1.9.3.185.10">
<h2>See Also</h2><span class="simplelist"><a class="xref" href="/docs/current/static/sql-insert.html" title="INSERT"><span class="refentrytitle">INSERT</span></a>, <a class="xref" href="/docs/current/static/sql-select.html" title="SELECT"><span class="refentrytitle">SELECT</span></a></span>
</div>
</div>
<div class="navfooter">
<hr/>
<table summary="Navigation footer" width="100%">
<tbody><tr>
<td align="left" width="40%"><a accesskey="p" href="/docs/current/static/sql-vacuum.html" title="VACUUM">Prev</a> </td>
<td align="center" width="20%"><a accesskey="u" href="/docs/current/static/sql-commands.html" title="SQL Commands">Up</a></td>
<td align="right" width="40%"> <a accesskey="n" href="/docs/current/static/reference-client.html" title="PostgreSQL Client Applications">Next</a></td>
</tr>
<tr>
<td align="left" valign="top" width="40%">VACUUM </td>
<td align="center" width="20%"><a accesskey="h" href="/docs/current/static/index.html" title="PostgreSQL 18.3 Documentation">Home</a></td>
<td align="right" valign="top" width="40%"> PostgreSQL Client Applications</td>
</tr>
</tbody></table>
</div>
</div>
<div id="docComments">
<h2>Submit correction</h2>
<p>
If you see anything in the documentation that is not correct, does not match
your experience with the particular feature or requires further clarification,
please use
<a href="/account/comments/new/18/sql-values.html/" rel="nofollow">this form</a>
to report a documentation issue.
</p>
</div>
</div> <!-- pgContentWrap -->
</div>
</div>
<!-- Footer -->
<footer id="footer">
<!-- Copyright -->
<div class="container">
<a href="/about/policies/">Policies</a> |
<a href="/about/policies/coc/">Code of Conduct</a> |
<a href="/about/">About PostgreSQL</a> |
<a href="/about/contact/">Contact</a><br/>
<p>Copyright © 1996-2026 The PostgreSQL Global Development Group</p>
</div>
</footer>
<script src="/media/js/main.js?54a05eb2"></script>
</body></html> |