gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

60 行
5.2KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!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>7.7. VALUES Lists</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="queries-limit.html" title="7.6. LIMIT and OFFSET" /><link rel="next" href="queries-with.html" title="7.8. WITH Queries (Common Table Expressions)" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">7.7. <code xmlns="http://www.w3.org/1999/xhtml" class="literal">VALUES</code> Lists</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="queries-limit.html" title="7.6. LIMIT and OFFSET">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="queries.html" title="Chapter 7. Queries">Up</a></td><th width="60%" align="center">Chapter 7. Queries</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="queries-with.html" title="7.8. WITH Queries (Common Table Expressions)">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="QUERIES-VALUES"><div class="titlepage"><div><div><h2 class="title" style="clear: both">7.7. <code class="literal">VALUES</code> Lists</h2></div></div></div><a id="id-1.5.6.11.2" class="indexterm"></a><p>
  3. <code class="literal">VALUES</code> provides a way to generate a <span class="quote">“<span class="quote">constant table</span>”</span>
  4. that can be used in a query without having to actually create and populate
  5. a table on-disk. The syntax is
  6. </p><pre class="synopsis">
  7. VALUES ( <em class="replaceable"><code>expression</code></em> [, ...] ) [, ...]
  8. </pre><p>
  9. Each parenthesized list of expressions generates a row in the table.
  10. The lists must all have the same number of elements (i.e., the number
  11. of columns in the table), and corresponding entries in each list must
  12. have compatible data types. The actual data type assigned to each column
  13. of the result is determined using the same rules as for <code class="literal">UNION</code>
  14. (see <a class="xref" href="typeconv-union-case.html" title="10.5. UNION, CASE, and Related Constructs">Section 10.5</a>).
  15. </p><p>
  16. As an example:
  17. </p><pre class="programlisting">
  18. VALUES (1, 'one'), (2, 'two'), (3, 'three');
  19. </pre><p>
  20. will return a table of two columns and three rows. It's effectively
  21. equivalent to:
  22. </p><pre class="programlisting">
  23. SELECT 1 AS column1, 'one' AS column2
  24. UNION ALL
  25. SELECT 2, 'two'
  26. UNION ALL
  27. SELECT 3, 'three';
  28. </pre><p>
  29. By default, <span class="productname">PostgreSQL</span> assigns the names
  30. <code class="literal">column1</code>, <code class="literal">column2</code>, etc. to the columns of a
  31. <code class="literal">VALUES</code> table. The column names are not specified by the
  32. SQL standard and different database systems do it differently, so
  33. it's usually better to override the default names with a table alias
  34. list, like this:
  35. </p><pre class="programlisting">
  36. =&gt; SELECT * FROM (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t (num,letter);
  37. num | letter
  38. -----+--------
  39. 1 | one
  40. 2 | two
  41. 3 | three
  42. (3 rows)
  43. </pre><p>
  44. </p><p>
  45. Syntactically, <code class="literal">VALUES</code> followed by expression lists is
  46. treated as equivalent to:
  47. </p><pre class="synopsis">
  48. SELECT <em class="replaceable"><code>select_list</code></em> FROM <em class="replaceable"><code>table_expression</code></em>
  49. </pre><p>
  50. and can appear anywhere a <code class="literal">SELECT</code> can. For example, you can
  51. use it as part of a <code class="literal">UNION</code>, or attach a
  52. <em class="replaceable"><code>sort_specification</code></em> (<code class="literal">ORDER BY</code>,
  53. <code class="literal">LIMIT</code>, and/or <code class="literal">OFFSET</code>) to it. <code class="literal">VALUES</code>
  54. is most commonly used as the data source in an <code class="command">INSERT</code> command,
  55. and next most commonly as a subquery.
  56. </p><p>
  57. For more information see <a class="xref" href="sql-values.html" title="VALUES"><span class="refentrytitle">VALUES</span></a>.
  58. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="queries-limit.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="queries.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="queries-with.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">7.6. <code class="literal">LIMIT</code> and <code class="literal">OFFSET</code> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 7.8. <code class="literal">WITH</code> Queries (Common Table Expressions)</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1