{"Entry":{"collection":"sql","key":"values","name":"VALUES","aliases":["values"],"metadata":{"aliases":["values"],"changed_in":["8.4"],"changes":[{"from":"8.1","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"8.2"},{"from":"8.2","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters","notes","examples"],"removed":[]},"status":"changed","synopsis":null,"to":"8.3"},{"from":"8.3","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","compatibility"],"removed":[]},"status":"changed","synopsis":{"added":["[ OFFSET start [ ROW | ROWS ] ]","[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]"],"removed":[]},"to":"8.4"},{"from":"9.6","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","examples"],"removed":[]},"status":"changed","synopsis":null,"to":"10"},{"from":"12","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters"],"removed":[]},"status":"changed","synopsis":null,"to":"13"},{"from":"14","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["examples"],"removed":[]},"status":"changed","synopsis":null,"to":"15"},{"from":"18","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["examples"],"removed":[]},"status":"changed","synopsis":null,"to":"19"}],"content_hash":"1cc63d73008300d643463bf161344c8529ab3a685b22f3cdfa42e745cba02fd1","derived_content_hash":"c234703e6ba044fb92b7758f249ff0dd5058c439d5bfa48ceafbcc21adeb7957","documentation_refresh":{"batch":"20261113","original_source_rev":"wiki-repair-20261023:75f6d9e6c96fd535e0c0124af31e18dcc3fd476ecc7820e89a35c449fc9db99a","versions":{"14":"14.25","15":"15.20","16":"16.16","17":"17.12","18":"18.7","19":"19rc2"}},"editorial":{},"first_version":"8.2","group":"query","imported_at":"2026-09-30T17:43:39.10348+08:00","last_version":"20","name":"VALUES","object":"","position":11008,"present_in":["8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"purpose":"compute a set of rows","purpose_zh":"","related":["insert","select"],"repair_provenance":{"original_source_revision":"wiki-repair-20261023:a13863705eed5f58594eec688859f3ca1a61ad4b4288bc50b5fb15cb4d4ecdf8","receipt_sha256":"2e1515618e139013a10539cfbc6ce1bf24c5e0c80d05383155cafcc18a2d6f2a","repair":"wiki-repair-20261023"},"slug":"values","source_rev":"wiki-repair-20261023:75f6d9e6c96fd535e0c0124af31e18dcc3fd476ecc7820e89a35c449fc9db99a","synopsis":"VALUES ( expression [, ...] ) [, ...]\n[ ORDER BY sort_expression [ ASC | DESC | USING operator ] [, ...] ]\n[ LIMIT { count | ALL } ]\n[ OFFSET start [ ROW | ROWS ] ]\n[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]","verb":"VALUES"}},"Definition":{"Collection":"sql","Key":"values","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"values","SourceRevision":"wiki-repair-20261023:75f6d9e6c96fd535e0c0124af31e18dcc3fd476ecc7820e89a35c449fc9db99a","Facts":{"anchor":"SQL-VALUES","description_zh":"计算一组行","description_zh_html":"\u003cpre\u003eVALUES ( expression [, ...] ) [, ...]\n[ ORDER BY sort_expression [ ASC | DESC | USING operator ] [, ...] ]\n[ LIMIT { count | ALL } ]\n[ OFFSET start [ ROW | ROWS ] ]\n[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 计算由值表达式指定的一个行值或一组行值。它最常用于在更大的命令中生成一个\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e常量表\u003c/span\u003e”\u003c/span\u003e，但也可以单独使用。\n  \u003c/p\u003e\u003cp\u003e\n   当指定多于一行时，所有行都必须具有相同数量的元素。结果表各列的数据类型由出现在该列中的表达式的显式类型或推断类型组合决定，所用规则与\n   \u003ccode class=\"literal\"\u003eUNION\u003c/code\u003e 相同（见\u003ca class=\"xref\" href=\"/zh/docs/18/typeconv-union-case.html\" title=\"10.5. UNION、CASE及相关结构\"\u003e第 10.5 节\u003c/a\u003e）。\n  \u003c/p\u003e\u003cp\u003e\n   在更大的命令中，从语法上说，凡是允许出现 \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e 的地方，也都允许出现 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e。因为在语法中它被当作\n   \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e 处理，所以可以对 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e\n   命令使用 \u003ccode class=\"literal\"\u003eORDER BY\u003c/code\u003e、\u003ccode class=\"literal\"\u003eLIMIT\u003c/code\u003e（或者等效的 \u003ccode class=\"literal\"\u003eFETCH FIRST\u003c/code\u003e）以及 \u003ccode class=\"literal\"\u003eOFFSET\u003c/code\u003e 子句。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\u003c/h2\u003e\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"ZH18-AUTO-VALUES-VARLISTENTRY-1\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      要在结果表（行集合）中相应位置计算并插入的常量或表达式。在出现在 \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e 顶层的\n      \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 列表中，\u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e 可以用\n      \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e 替代，以表示应插入目标列的默认值。当 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 出现在其他上下文中时，不能使用\n      \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-VALUES-VARLISTENTRY-2\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003esort_expression\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      一个指示结果行如何排序的表达式或整数常量。该表达式可以将 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 结果的列引用为 \u003ccode class=\"literal\"\u003ecolumn1\u003c/code\u003e、\u003ccode class=\"literal\"\u003ecolumn2\u003c/code\u003e 等。详细信息参见 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e 文档中的 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html#SQL-ORDERBY\" title=\"ORDER BY 子句\"\u003eORDER BY 子句\u003c/a\u003e。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-VALUES-VARLISTENTRY-3\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoperator\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      一个排序操作符。详细信息参见 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e 文档中的 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html#SQL-ORDERBY\" title=\"ORDER BY 子句\"\u003eORDER BY 子句\u003c/a\u003e。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-VALUES-VARLISTENTRY-4\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      返回的最大行数。详细信息参见 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e 文档中的 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html#SQL-LIMIT\" title=\"LIMIT 子句\"\u003eLIMIT 子句\u003c/a\u003e。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-VALUES-VARLISTENTRY-5\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003estart\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      开始返回行之前要跳过的行数。详细信息参见 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e 文档中的 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html#SQL-LIMIT\" title=\"LIMIT 子句\"\u003eLIMIT 子句\u003c/a\u003e。\n     \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e注解\u003c/h2\u003e\u003cp\u003e\n   应避免使用行数非常多的 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 列表，因为这可能导致内存不足错误或性能不佳。出现在 \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e 中的\n   \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 属于一种特殊情况（因为所需的列类型可以从 \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e 的目标表得知，并且无须通过扫描\n   \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 列表来推断），因此它能处理比其他上下文中实际可行的更大的列表。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e\n   一个独立的 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 命令：\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nVALUES (1, 'one'), (2, 'two'), (3, 'three');\n\u003c/pre\u003e\u003cp\u003e\n\n   这将返回一个两列三行的表。它实际上等效于：\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nSELECT 1 AS column1, 'one' AS column2\nUNION ALL\nSELECT 2, 'two'\nUNION ALL\nSELECT 3, 'three';\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   更常见的是，\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 会用在更大的 SQL 命令中。最常见的用法是在 \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e 中：\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nINSERT INTO films (code, title, did, date_prod, kind)\n    VALUES ('T_601', 'Yojimbo', 106, '1961-06-16', 'Drama');\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   在 \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e 的上下文中，\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 列表中的项可以写成 \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e，表示此处应使用该列的默认值，而不是显式指定一个值：\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nINSERT INTO films VALUES\n    ('UA502', 'Bananas', 105, DEFAULT, 'Comedy', '82 minutes'),\n    ('T_601', 'Yojimbo', 106, DEFAULT, 'Drama', DEFAULT);\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 也可以用在原本可以编写子 \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e 的地方，例如在 \u003ccode class=\"literal\"\u003eFROM\u003c/code\u003e 子句中：\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nSELECT f.*\n  FROM films f, (VALUES('MGM', 'Horror'), ('UA', 'Sci-Fi')) AS t (studio, kind)\n  WHERE f.studio = t.studio AND f.kind = t.kind;\n\nUPDATE employees SET salary = salary * v.increase\n  FROM (VALUES(1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase)\n  WHERE employees.depno = v.depno AND employees.sales \u0026gt;= v.target;\n\u003c/pre\u003e\u003cp\u003e\n\n   注意，在 \u003ccode class=\"literal\"\u003eFROM\u003c/code\u003e 子句中使用 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 时，表别名是可选的。为 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 列表的列指定别名也是可选的，但这样做是一个好习惯。（在 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 中，\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 的默认列名是\n   \u003ccode class=\"literal\"\u003ecolumn1\u003c/code\u003e、\u003ccode class=\"literal\"\u003ecolumn2\u003c/code\u003e 等，但在其他数据库系统中，这些名称可能不同。）\n\u003c/p\u003e\u003cp\u003e\n   当在 \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e 中使用 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 时，所有值都会自动转换为相应目标列的数据类型。当它用于其他上下文时，可能有必要指定正确的数据类型。如果各项都是带引号的字符串常量，只需转换第一项，就足以为所有项确定假定的数据类型：\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nSELECT * FROM machines\nWHERE ip_address IN (VALUES('192.168.0.1'::inet), ('192.168.0.10'), ('192.168.1.43'));\n\u003c/pre\u003e\u003cdiv class=\"tip\"\u003e\u003ch3 class=\"title\"\u003e提示\u003c/h3\u003e\u003cp\u003e\n    对于简单的 \u003ccode class=\"literal\"\u003eIN\u003c/code\u003e 测试，最好使用 \u003ccode class=\"literal\"\u003eIN\u003c/code\u003e 的\u003ca class=\"link\" href=\"/zh/docs/18/functions-comparisons.html#FUNCTIONS-COMPARISONS-IN-SCALAR\" title=\"9.25.1. IN\"\u003e标量列表\u003c/a\u003e形式，而不是写一个像上面那样的 \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 查询。标量列表方法写法更简洁，而且通常效率更高。\n   \u003c/p\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e 符合 SQL 标准。\u003ccode class=\"literal\"\u003eLIMIT\u003c/code\u003e 和 \u003ccode class=\"literal\"\u003eOFFSET\u003c/code\u003e 是\n   \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 扩展，另见 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/zh/docs/18/sql-insert.html\" title=\"INSERT\"\u003e\u003cspan class=\"refentrytitle\"\u003eINSERT\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","documentation_revision":{"inputs":[{"file":"sql-values.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"0ec00df897e3b02e5ca8f50a100750aec01dfefb024f13e4c3a7b8abdd5d54f1","version":"18.7"},{"file":"sql-values.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"d1db2bf2b3352b1f2641650d94e844c8bda8b5c1d37098fd6ab986c19a21c66d","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"},"file":"sql-values.html","lang":"en","name":"VALUES","purpose":"compute a set of rows","purpose_zh":"计算一组行","related":["insert","select"],"sections":[{"html":"\u003cp\u003e\n\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e computes a row value or set of row values\n   specified by value expressions.  It is most commonly used to generate\n   a \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003econstant table\u003c/span\u003e”\u003c/span\u003e within a larger command, but it can be\n   used on its own.\n  \u003c/p\u003e\u003cp\u003e\n   When more than one row is specified, all the rows must have the same\n   number of elements.  The data types of the resulting table's columns are\n   determined by combining the explicit or inferred types of the expressions\n   appearing in that column, using the same rules as for \u003ccode class=\"literal\"\u003eUNION\u003c/code\u003e\n   (see \u003ca class=\"xref\" href=\"/docs/18/typeconv-union-case.html\" title=\"10.5. UNION, CASE, and Related Constructs\"\u003eSection 10.5\u003c/a\u003e).\n  \u003c/p\u003e\u003cp\u003e\n   Within larger commands, \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e is syntactically allowed\n   anywhere that \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e is.  Because it is treated like a\n   \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e by the grammar, it is possible to use\n   the \u003ccode class=\"literal\"\u003eORDER BY\u003c/code\u003e, \u003ccode class=\"literal\"\u003eLIMIT\u003c/code\u003e (or\n   equivalently \u003ccode class=\"literal\"\u003eFETCH FIRST\u003c/code\u003e),\n   and \u003ccode class=\"literal\"\u003eOFFSET\u003c/code\u003e clauses with a\n   \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e command.\n  \u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      A constant or expression to compute and insert at the indicated place\n      in the resulting table (set of rows).  In a \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e list\n      appearing at the top level of an \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, an\n      \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e can be replaced\n      by \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e to indicate that the destination column's\n      default value should be inserted.  \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e cannot\n      be used when \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e appears in other contexts.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003esort_expression\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      An expression or integer constant indicating how to sort the result\n      rows.  This expression can refer to the columns of the\n      \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e result as \u003ccode class=\"literal\"\u003ecolumn1\u003c/code\u003e, \u003ccode class=\"literal\"\u003ecolumn2\u003c/code\u003e,\n      etc.  For more details see\n      \u003ca class=\"xref\" href=\"/docs/18/sql-select.html#SQL-ORDERBY\" title=\"ORDER BY Clause\"\u003eORDER BY Clause\u003c/a\u003e\n      in the \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoperator\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      A sorting operator.  For details see\n      \u003ca class=\"xref\" href=\"/docs/18/sql-select.html#SQL-ORDERBY\" title=\"ORDER BY Clause\"\u003eORDER BY Clause\u003c/a\u003e\n      in the \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      The maximum number of rows to return.  For details see\n      \u003ca class=\"xref\" href=\"/docs/18/sql-select.html#SQL-LIMIT\" title=\"LIMIT Clause\"\u003eLIMIT Clause\u003c/a\u003e\n      in the \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003estart\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      The number of rows to skip before starting to return rows.\n      For details see \u003ca class=\"xref\" href=\"/docs/18/sql-select.html#SQL-LIMIT\" title=\"LIMIT Clause\"\u003eLIMIT Clause\u003c/a\u003e\n      in the \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003e\n\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e lists with very large numbers of rows should be avoided,\n   as you might encounter out-of-memory failures or poor performance.\n   \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e appearing within \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e is a special case\n   (because the desired column types are known from the \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e's\n   target table, and need not be inferred by scanning the \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e\n   list), so it can handle larger lists than are practical in other contexts.\n  \u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003e\n   A bare \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e command:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nVALUES (1, 'one'), (2, 'two'), (3, 'three');\n\u003c/pre\u003e\u003cp\u003e\n\n   This will return a table of two columns and three rows.  It's effectively\n   equivalent to:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nSELECT 1 AS column1, 'one' AS column2\nUNION ALL\nSELECT 2, 'two'\nUNION ALL\nSELECT 3, 'three';\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   More usually, \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e is used within a larger SQL command.\n   The most common use is in \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nINSERT INTO films (code, title, did, date_prod, kind)\n    VALUES ('T_601', 'Yojimbo', 106, '1961-06-16', 'Drama');\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   In the context of \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, entries of a \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e list\n   can be \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e to indicate that the column default\n   should be used here instead of specifying a value:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nINSERT INTO films VALUES\n    ('UA502', 'Bananas', 105, DEFAULT, 'Comedy', '82 minutes'),\n    ('T_601', 'Yojimbo', 106, DEFAULT, 'Drama', DEFAULT);\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e can also be used where a sub-\u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e might\n   be written, for example in a \u003ccode class=\"literal\"\u003eFROM\u003c/code\u003e clause:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nSELECT f.*\n  FROM films f, (VALUES('MGM', 'Horror'), ('UA', 'Sci-Fi')) AS t (studio, kind)\n  WHERE f.studio = t.studio AND f.kind = t.kind;\n\nUPDATE employees SET salary = salary * v.increase\n  FROM (VALUES(1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase)\n  WHERE employees.depno = v.depno AND employees.sales \u0026gt;= v.target;\n\u003c/pre\u003e\u003cp\u003e\n\n   Note that if \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e is used in a \u003ccode class=\"literal\"\u003eFROM\u003c/code\u003e\n   clause, a table alias is optional.  Assigning alias names to the columns\n   of the \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e list is optional, but is good practice.\n   (The default column names for \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e are \u003ccode class=\"literal\"\u003ecolumn1\u003c/code\u003e,\n   \u003ccode class=\"literal\"\u003ecolumn2\u003c/code\u003e, etc. in \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e, but\n   these names might be different in other database systems.)\n  \u003c/p\u003e\u003cp\u003e\n   When \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e is used in \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, the values are all\n   automatically coerced to the data type of the corresponding destination\n   column.  When it's used in other contexts, it might be necessary to specify\n   the correct data type.  If the entries are all quoted literal constants,\n   coercing the first is sufficient to determine the assumed type for all:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nSELECT * FROM machines\nWHERE ip_address IN (VALUES('192.168.0.1'::inet), ('192.168.0.10'), ('192.168.1.43'));\n\u003c/pre\u003e\u003cdiv class=\"tip\"\u003e\u003ch3 class=\"title\"\u003eTip\u003c/h3\u003e\u003cp\u003e\n    For simple \u003ccode class=\"literal\"\u003eIN\u003c/code\u003e tests, it's better to rely on the\n    \u003ca class=\"link\" href=\"/docs/18/functions-comparisons.html#FUNCTIONS-COMPARISONS-IN-SCALAR\" title=\"9.25.1. IN\"\u003elist-of-scalars\u003c/a\u003e\n    form of \u003ccode class=\"literal\"\u003eIN\u003c/code\u003e than to write a \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e\n    query as shown above.  The list of scalars method requires less writing\n    and is often more efficient.\n   \u003c/p\u003e\u003c/div\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e conforms to the SQL standard.\n   \u003ccode class=\"literal\"\u003eLIMIT\u003c/code\u003e and \u003ccode class=\"literal\"\u003eOFFSET\u003c/code\u003e are\n   \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extensions; see also\n   under \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e.\n  \u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/docs/18/sql-insert.html\" title=\"INSERT\"\u003e\u003cspan class=\"refentrytitle\"\u003eINSERT\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"VALUES ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e [, ...] ) [, ...]\n    [ ORDER BY \u003cem class=\"replaceable\"\u003e\u003ccode\u003esort_expression\u003c/code\u003e\u003c/em\u003e [ ASC | DESC | USING \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoperator\u003c/code\u003e\u003c/em\u003e ] [, ...] ]\n    [ LIMIT { \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e | ALL } ]\n    [ OFFSET \u003cem class=\"replaceable\"\u003e\u003ccode\u003estart\u003c/code\u003e\u003c/em\u003e [ ROW | ROWS ] ]\n    [ FETCH { FIRST | NEXT } [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e ] { ROW | ROWS } ONLY ]","synopsis_text":"VALUES ( expression [, ...] ) [, ...]\n[ ORDER BY sort_expression [ ASC | DESC | USING operator ] [, ...] ]\n[ LIMIT { count | ALL } ]\n[ OFFSET start [ ROW | ROWS ] ]\n[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/sql-values.html","sha256":"661041c55eec3305d18af8a06541851425847de6d22ce8626372062dafd49869"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"zh_from":"same-version-manual"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"values","SourceDatabase":"center","Version":"18","Locale":"en","Title":"VALUES","Summary":"compute a set of rows","BodyHTML":"\u003cpre\u003eVALUES ( expression [, ...] ) [, ...]\n[ ORDER BY sort_expression [ ASC | DESC | USING operator ] [, ...] ]\n[ LIMIT { count | ALL } ]\n[ OFFSET start [ ROW | ROWS ] ]\n[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]\u003c/pre\u003e\u003csection\u003e\u003ch2\u003eDescription\u003c/h2\u003e\u003cp\u003e\n\u003ccode\u003eVALUES\u003c/code\u003e computes a row value or set of row values\n   specified by value expressions.  It is most commonly used to generate\n   a \u003cspan\u003e“\u003cspan\u003econstant table\u003c/span\u003e”\u003c/span\u003e within a larger command, but it can be\n   used on its own.\n  \u003c/p\u003e\u003cp\u003e\n   When more than one row is specified, all the rows must have the same\n   number of elements.  The data types of the resulting table\u0026#39;s columns are\n   determined by combining the explicit or inferred types of the expressions\n   appearing in that column, using the same rules as for \u003ccode\u003eUNION\u003c/code\u003e\n   (see \u003ca href=\"/docs/18/typeconv-union-case.html\" rel=\"nofollow\"\u003eSection 10.5\u003c/a\u003e).\n  \u003c/p\u003e\u003cp\u003e\n   Within larger commands, \u003ccode\u003eVALUES\u003c/code\u003e is syntactically allowed\n   anywhere that \u003ccode\u003eSELECT\u003c/code\u003e is.  Because it is treated like a\n   \u003ccode\u003eSELECT\u003c/code\u003e by the grammar, it is possible to use\n   the \u003ccode\u003eORDER BY\u003c/code\u003e, \u003ccode\u003eLIMIT\u003c/code\u003e (or\n   equivalently \u003ccode\u003eFETCH FIRST\u003c/code\u003e),\n   and \u003ccode\u003eOFFSET\u003c/code\u003e clauses with a\n   \u003ccode\u003eVALUES\u003c/code\u003e command.\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eParameters\u003c/h2\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      A constant or expression to compute and insert at the indicated place\n      in the resulting table (set of rows).  In a \u003ccode\u003eVALUES\u003c/code\u003e list\n      appearing at the top level of an \u003ccode\u003eINSERT\u003c/code\u003e, an\n      \u003cem\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e can be replaced\n      by \u003ccode\u003eDEFAULT\u003c/code\u003e to indicate that the destination column\u0026#39;s\n      default value should be inserted.  \u003ccode\u003eDEFAULT\u003c/code\u003e cannot\n      be used when \u003ccode\u003eVALUES\u003c/code\u003e appears in other contexts.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003esort_expression\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      An expression or integer constant indicating how to sort the result\n      rows.  This expression can refer to the columns of the\n      \u003ccode\u003eVALUES\u003c/code\u003e result as \u003ccode\u003ecolumn1\u003c/code\u003e, \u003ccode\u003ecolumn2\u003c/code\u003e,\n      etc.  For more details see\n      \u003ca href=\"/docs/18/sql-select.html#SQL-ORDERBY\" title=\"ORDER BY Clause\" rel=\"nofollow\"\u003eORDER BY Clause\u003c/a\u003e\n      in the \u003ca href=\"/docs/18/sql-select.html\" title=\"SELECT\" rel=\"nofollow\"\u003e\u003cspan\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003eoperator\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      A sorting operator.  For details see\n      \u003ca href=\"/docs/18/sql-select.html#SQL-ORDERBY\" title=\"ORDER BY Clause\" rel=\"nofollow\"\u003eORDER BY Clause\u003c/a\u003e\n      in the \u003ca href=\"/docs/18/sql-select.html\" title=\"SELECT\" rel=\"nofollow\"\u003e\u003cspan\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      The maximum number of rows to return.  For details see\n      \u003ca href=\"/docs/18/sql-select.html#SQL-LIMIT\" title=\"LIMIT Clause\" rel=\"nofollow\"\u003eLIMIT Clause\u003c/a\u003e\n      in the \u003ca href=\"/docs/18/sql-select.html\" title=\"SELECT\" rel=\"nofollow\"\u003e\u003cspan\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003estart\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      The number of rows to skip before starting to return rows.\n      For details see \u003ca href=\"/docs/18/sql-select.html#SQL-LIMIT\" title=\"LIMIT Clause\" rel=\"nofollow\"\u003eLIMIT Clause\u003c/a\u003e\n      in the \u003ca href=\"/docs/18/sql-select.html\" title=\"SELECT\" rel=\"nofollow\"\u003e\u003cspan\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eNotes\u003c/h2\u003e\u003cp\u003e\n\u003ccode\u003eVALUES\u003c/code\u003e lists with very large numbers of rows should be avoided,\n   as you might encounter out-of-memory failures or poor performance.\n   \u003ccode\u003eVALUES\u003c/code\u003e appearing within \u003ccode\u003eINSERT\u003c/code\u003e is a special case\n   (because the desired column types are known from the \u003ccode\u003eINSERT\u003c/code\u003e\u0026#39;s\n   target table, and need not be inferred by scanning the \u003ccode\u003eVALUES\u003c/code\u003e\n   list), so it can handle larger lists than are practical in other contexts.\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eExamples\u003c/h2\u003e\u003cp\u003e\n   A bare \u003ccode\u003eVALUES\u003c/code\u003e command:\n\n\u003c/p\u003e\u003cpre\u003e\nVALUES (1, \u0026#39;one\u0026#39;), (2, \u0026#39;two\u0026#39;), (3, \u0026#39;three\u0026#39;);\n\u003c/pre\u003e\u003cp\u003e\n\n   This will return a table of two columns and three rows.  It\u0026#39;s effectively\n   equivalent to:\n\n\u003c/p\u003e\u003cpre\u003e\nSELECT 1 AS column1, \u0026#39;one\u0026#39; AS column2\nUNION ALL\nSELECT 2, \u0026#39;two\u0026#39;\nUNION ALL\nSELECT 3, \u0026#39;three\u0026#39;;\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   More usually, \u003ccode\u003eVALUES\u003c/code\u003e is used within a larger SQL command.\n   The most common use is in \u003ccode\u003eINSERT\u003c/code\u003e:\n\n\u003c/p\u003e\u003cpre\u003e\nINSERT INTO films (code, title, did, date_prod, kind)\n    VALUES (\u0026#39;T_601\u0026#39;, \u0026#39;Yojimbo\u0026#39;, 106, \u0026#39;1961-06-16\u0026#39;, \u0026#39;Drama\u0026#39;);\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   In the context of \u003ccode\u003eINSERT\u003c/code\u003e, entries of a \u003ccode\u003eVALUES\u003c/code\u003e list\n   can be \u003ccode\u003eDEFAULT\u003c/code\u003e to indicate that the column default\n   should be used here instead of specifying a value:\n\n\u003c/p\u003e\u003cpre\u003e\nINSERT INTO films VALUES\n    (\u0026#39;UA502\u0026#39;, \u0026#39;Bananas\u0026#39;, 105, DEFAULT, \u0026#39;Comedy\u0026#39;, \u0026#39;82 minutes\u0026#39;),\n    (\u0026#39;T_601\u0026#39;, \u0026#39;Yojimbo\u0026#39;, 106, DEFAULT, \u0026#39;Drama\u0026#39;, DEFAULT);\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n\u003ccode\u003eVALUES\u003c/code\u003e can also be used where a sub-\u003ccode\u003eSELECT\u003c/code\u003e might\n   be written, for example in a \u003ccode\u003eFROM\u003c/code\u003e clause:\n\n\u003c/p\u003e\u003cpre\u003e\nSELECT f.*\n  FROM films f, (VALUES(\u0026#39;MGM\u0026#39;, \u0026#39;Horror\u0026#39;), (\u0026#39;UA\u0026#39;, \u0026#39;Sci-Fi\u0026#39;)) AS t (studio, kind)\n  WHERE f.studio = t.studio AND f.kind = t.kind;\n\nUPDATE employees SET salary = salary * v.increase\n  FROM (VALUES(1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase)\n  WHERE employees.depno = v.depno AND employees.sales \u0026gt;= v.target;\n\u003c/pre\u003e\u003cp\u003e\n\n   Note that if \u003ccode\u003eVALUES\u003c/code\u003e is used in a \u003ccode\u003eFROM\u003c/code\u003e\n   clause, a table alias is optional.  Assigning alias names to the columns\n   of the \u003ccode\u003eVALUES\u003c/code\u003e list is optional, but is good practice.\n   (The default column names for \u003ccode\u003eVALUES\u003c/code\u003e are \u003ccode\u003ecolumn1\u003c/code\u003e,\n   \u003ccode\u003ecolumn2\u003c/code\u003e, etc. in \u003cspan\u003ePostgreSQL\u003c/span\u003e, but\n   these names might be different in other database systems.)\n  \u003c/p\u003e\u003cp\u003e\n   When \u003ccode\u003eVALUES\u003c/code\u003e is used in \u003ccode\u003eINSERT\u003c/code\u003e, the values are all\n   automatically coerced to the data type of the corresponding destination\n   column.  When it\u0026#39;s used in other contexts, it might be necessary to specify\n   the correct data type.  If the entries are all quoted literal constants,\n   coercing the first is sufficient to determine the assumed type for all:\n\n\u003c/p\u003e\u003cpre\u003e\nSELECT * FROM machines\nWHERE ip_address IN (VALUES(\u0026#39;192.168.0.1\u0026#39;::inet), (\u0026#39;192.168.0.10\u0026#39;), (\u0026#39;192.168.1.43\u0026#39;));\n\u003c/pre\u003e\u003cdiv\u003e\u003ch3\u003eTip\u003c/h3\u003e\u003cp\u003e\n    For simple \u003ccode\u003eIN\u003c/code\u003e tests, it\u0026#39;s better to rely on the\n    \u003ca href=\"/docs/18/functions-comparisons.html#FUNCTIONS-COMPARISONS-IN-SCALAR\" rel=\"nofollow\"\u003elist-of-scalars\u003c/a\u003e\n    form of \u003ccode\u003eIN\u003c/code\u003e than to write a \u003ccode\u003eVALUES\u003c/code\u003e\n    query as shown above.  The list of scalars method requires less writing\n    and is often more efficient.\n   \u003c/p\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eCompatibility\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eVALUES\u003c/code\u003e conforms to the SQL standard.\n   \u003ccode\u003eLIMIT\u003c/code\u003e and \u003ccode\u003eOFFSET\u003c/code\u003e are\n   \u003cspan\u003ePostgreSQL\u003c/span\u003e extensions; see also\n   under \u003ca href=\"/docs/18/sql-select.html\" title=\"SELECT\" rel=\"nofollow\"\u003e\u003cspan\u003eSELECT\u003c/span\u003e\u003c/a\u003e.\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/docs/18/sql-insert.html\" title=\"INSERT\" rel=\"nofollow\"\u003e\u003cspan\u003eINSERT\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/docs/18/sql-select.html\" title=\"SELECT\" rel=\"nofollow\"\u003e\u003cspan\u003eSELECT\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"wiki-repair-20261023:75f6d9e6c96fd535e0c0124af31e18dcc3fd476ecc7820e89a35c449fc9db99a","ContentHash":"3c493b1c6f4e0d5ac176b149bf705574bf78c82efc939af8812d8f2aa70cc8cc","Payload":{"related":["insert","select"],"sections":[{"html":"\u003cp\u003e\n\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e computes a row value or set of row values\n   specified by value expressions.  It is most commonly used to generate\n   a \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003econstant table\u003c/span\u003e”\u003c/span\u003e within a larger command, but it can be\n   used on its own.\n  \u003c/p\u003e\u003cp\u003e\n   When more than one row is specified, all the rows must have the same\n   number of elements.  The data types of the resulting table's columns are\n   determined by combining the explicit or inferred types of the expressions\n   appearing in that column, using the same rules as for \u003ccode class=\"literal\"\u003eUNION\u003c/code\u003e\n   (see \u003ca class=\"xref\" href=\"/docs/18/typeconv-union-case.html\" title=\"10.5. UNION, CASE, and Related Constructs\"\u003eSection 10.5\u003c/a\u003e).\n  \u003c/p\u003e\u003cp\u003e\n   Within larger commands, \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e is syntactically allowed\n   anywhere that \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e is.  Because it is treated like a\n   \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e by the grammar, it is possible to use\n   the \u003ccode class=\"literal\"\u003eORDER BY\u003c/code\u003e, \u003ccode class=\"literal\"\u003eLIMIT\u003c/code\u003e (or\n   equivalently \u003ccode class=\"literal\"\u003eFETCH FIRST\u003c/code\u003e),\n   and \u003ccode class=\"literal\"\u003eOFFSET\u003c/code\u003e clauses with a\n   \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e command.\n  \u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      A constant or expression to compute and insert at the indicated place\n      in the resulting table (set of rows).  In a \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e list\n      appearing at the top level of an \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, an\n      \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e can be replaced\n      by \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e to indicate that the destination column's\n      default value should be inserted.  \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e cannot\n      be used when \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e appears in other contexts.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003esort_expression\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      An expression or integer constant indicating how to sort the result\n      rows.  This expression can refer to the columns of the\n      \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e result as \u003ccode class=\"literal\"\u003ecolumn1\u003c/code\u003e, \u003ccode class=\"literal\"\u003ecolumn2\u003c/code\u003e,\n      etc.  For more details see\n      \u003ca class=\"xref\" href=\"/docs/18/sql-select.html#SQL-ORDERBY\" title=\"ORDER BY Clause\"\u003eORDER BY Clause\u003c/a\u003e\n      in the \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoperator\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      A sorting operator.  For details see\n      \u003ca class=\"xref\" href=\"/docs/18/sql-select.html#SQL-ORDERBY\" title=\"ORDER BY Clause\"\u003eORDER BY Clause\u003c/a\u003e\n      in the \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      The maximum number of rows to return.  For details see\n      \u003ca class=\"xref\" href=\"/docs/18/sql-select.html#SQL-LIMIT\" title=\"LIMIT Clause\"\u003eLIMIT Clause\u003c/a\u003e\n      in the \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003estart\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      The number of rows to skip before starting to return rows.\n      For details see \u003ca class=\"xref\" href=\"/docs/18/sql-select.html#SQL-LIMIT\" title=\"LIMIT Clause\"\u003eLIMIT Clause\u003c/a\u003e\n      in the \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e documentation.\n     \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003e\n\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e lists with very large numbers of rows should be avoided,\n   as you might encounter out-of-memory failures or poor performance.\n   \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e appearing within \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e is a special case\n   (because the desired column types are known from the \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e's\n   target table, and need not be inferred by scanning the \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e\n   list), so it can handle larger lists than are practical in other contexts.\n  \u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003e\n   A bare \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e command:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nVALUES (1, 'one'), (2, 'two'), (3, 'three');\n\u003c/pre\u003e\u003cp\u003e\n\n   This will return a table of two columns and three rows.  It's effectively\n   equivalent to:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nSELECT 1 AS column1, 'one' AS column2\nUNION ALL\nSELECT 2, 'two'\nUNION ALL\nSELECT 3, 'three';\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   More usually, \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e is used within a larger SQL command.\n   The most common use is in \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nINSERT INTO films (code, title, did, date_prod, kind)\n    VALUES ('T_601', 'Yojimbo', 106, '1961-06-16', 'Drama');\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   In the context of \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, entries of a \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e list\n   can be \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e to indicate that the column default\n   should be used here instead of specifying a value:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nINSERT INTO films VALUES\n    ('UA502', 'Bananas', 105, DEFAULT, 'Comedy', '82 minutes'),\n    ('T_601', 'Yojimbo', 106, DEFAULT, 'Drama', DEFAULT);\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e can also be used where a sub-\u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e might\n   be written, for example in a \u003ccode class=\"literal\"\u003eFROM\u003c/code\u003e clause:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nSELECT f.*\n  FROM films f, (VALUES('MGM', 'Horror'), ('UA', 'Sci-Fi')) AS t (studio, kind)\n  WHERE f.studio = t.studio AND f.kind = t.kind;\n\nUPDATE employees SET salary = salary * v.increase\n  FROM (VALUES(1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase)\n  WHERE employees.depno = v.depno AND employees.sales \u0026gt;= v.target;\n\u003c/pre\u003e\u003cp\u003e\n\n   Note that if \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e is used in a \u003ccode class=\"literal\"\u003eFROM\u003c/code\u003e\n   clause, a table alias is optional.  Assigning alias names to the columns\n   of the \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e list is optional, but is good practice.\n   (The default column names for \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e are \u003ccode class=\"literal\"\u003ecolumn1\u003c/code\u003e,\n   \u003ccode class=\"literal\"\u003ecolumn2\u003c/code\u003e, etc. in \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e, but\n   these names might be different in other database systems.)\n  \u003c/p\u003e\u003cp\u003e\n   When \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e is used in \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, the values are all\n   automatically coerced to the data type of the corresponding destination\n   column.  When it's used in other contexts, it might be necessary to specify\n   the correct data type.  If the entries are all quoted literal constants,\n   coercing the first is sufficient to determine the assumed type for all:\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nSELECT * FROM machines\nWHERE ip_address IN (VALUES('192.168.0.1'::inet), ('192.168.0.10'), ('192.168.1.43'));\n\u003c/pre\u003e\u003cdiv class=\"tip\"\u003e\u003ch3 class=\"title\"\u003eTip\u003c/h3\u003e\u003cp\u003e\n    For simple \u003ccode class=\"literal\"\u003eIN\u003c/code\u003e tests, it's better to rely on the\n    \u003ca class=\"link\" href=\"/docs/18/functions-comparisons.html#FUNCTIONS-COMPARISONS-IN-SCALAR\" title=\"9.25.1. IN\"\u003elist-of-scalars\u003c/a\u003e\n    form of \u003ccode class=\"literal\"\u003eIN\u003c/code\u003e than to write a \u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e\n    query as shown above.  The list of scalars method requires less writing\n    and is often more efficient.\n   \u003c/p\u003e\u003c/div\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eVALUES\u003c/code\u003e conforms to the SQL standard.\n   \u003ccode class=\"literal\"\u003eLIMIT\u003c/code\u003e and \u003ccode class=\"literal\"\u003eOFFSET\u003c/code\u003e are\n   \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extensions; see also\n   under \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e.\n  \u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/docs/18/sql-insert.html\" title=\"INSERT\"\u003e\u003cspan class=\"refentrytitle\"\u003eINSERT\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/docs/18/sql-select.html\" title=\"SELECT\"\u003e\u003cspan class=\"refentrytitle\"\u003eSELECT\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","synopsis_html":"VALUES ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e [, ...] ) [, ...]\n    [ ORDER BY \u003cem class=\"replaceable\"\u003e\u003ccode\u003esort_expression\u003c/code\u003e\u003c/em\u003e [ ASC | DESC | USING \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoperator\u003c/code\u003e\u003c/em\u003e ] [, ...] ]\n    [ LIMIT { \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e | ALL } ]\n    [ OFFSET \u003cem class=\"replaceable\"\u003e\u003ccode\u003estart\u003c/code\u003e\u003c/em\u003e [ ROW | ROWS ] ]\n    [ FETCH { FIRST | NEXT } [ \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e ] { ROW | ROWS } ONLY ]","synopsis_text":"VALUES ( expression [, ...] ) [, ...]\n[ ORDER BY sort_expression [ ASC | DESC | USING operator ] [, ...] ]\n[ LIMIT { count | ALL } ]\n[ OFFSET start [ ROW | ROWS ] ]\n[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]"}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
