⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 values.7

📁 PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开发团队说,该版本将加速更多企业向该数据库移植.核心开发成员之一Bruce Momjian表示,在新版PostgreSQL
💻 7
字号:
.\\" auto-generated by docbook2man-spec $Revision: 1.1.1.1 $.TH "VALUES" "" "2008-01-03" "SQL - Language Statements" "SQL Commands".SH NAMEVALUES \- compute a set of rows.SH SYNOPSIS.sp.nfVALUES ( \fIexpression\fR [, ...] ) [, ...]    [ ORDER BY \fIsort_expression\fR [ ASC | DESC | USING \fIoperator\fR ] [, ...] ]    [ LIMIT { \fIcount\fR | ALL } ]    [ OFFSET \fIstart\fR ].sp.fi.SH "DESCRIPTION".PP\fBVALUES\fR computes a row value or set of row valuesspecified by value expressions. It is most commonly used to generatea ``constant table'' within a larger command, but it can beused on its own..PPWhen more than one row is specified, all the rows must have the samenumber of elements. The data types of the resulting table's columns aredetermined by combining the explicit or inferred types of the expressionsappearing in that column, using the same rules as for UNION(see in the documentation)..PPWithin larger commands, \fBVALUES\fR is syntactically allowedanywhere that \fBSELECT\fR is. Because it is treated like a\fBSELECT\fR by the grammar, it is possible to use the ORDERBY, LIMIT, and OFFSET clauses with a\fBVALUES\fR command..SH "PARAMETERS".TP\fB\fIexpression\fB\fRA constant or expression to compute and insert at the indicated placein the resulting table (set of rows). In a \fBVALUES\fR listappearing at the top level of an \fBINSERT\fR, an\fIexpression\fR can be replacedby DEFAULT to indicate that the destination column'sdefault value should be inserted. DEFAULT cannotbe used when \fBVALUES\fR appears in other contexts..TP\fB\fIsort_expression\fB\fRAn expression or integer constant indicating how to sort the resultrows. This expression may refer to the columns of the\fBVALUES\fR result as column1, column2,etc. For more details seeORDER BY Clause [\fBselect\fR(7)]..TP\fB\fIoperator\fB\fRA sorting operator. For details seeORDER BY Clause [\fBselect\fR(7)]..TP\fB\fIcount\fB\fRThe maximum number of rows to return. For details seeLIMIT Clause [\fBselect\fR(7)]..TP\fB\fIstart\fB\fRThe number of rows to skip before starting to return rows.For details see LIMIT Clause [\fBselect\fR(7)]..SH "NOTES".PP\fBVALUES\fR lists with very large numbers of rows should be avoided,as you may encounter out-of-memory failures or poor performance.\fBVALUES\fR appearing within \fBINSERT\fR is a special case(because the desired column types are known from the \fBINSERT\fR'starget table, and need not be inferred by scanning the \fBVALUES\fRlist), so it can handle larger lists than are practical in other contexts..SH "EXAMPLES".PPA bare \fBVALUES\fR command:.sp.nfVALUES (1, 'one'), (2, 'two'), (3, 'three');.sp.fiThis will return a table of two columns and three rows. It's effectivelyequivalent to.sp.nfSELECT 1 AS column1, 'one' AS column2UNION ALLSELECT 2, 'two'UNION ALLSELECT 3, 'three';.sp.fi.PPMore usually, \fBVALUES\fR is used within a larger SQL command.The most common use is in \fBINSERT\fR:.sp.nfINSERT INTO films (code, title, did, date_prod, kind)    VALUES ('T_601', 'Yojimbo', 106, '1961-06-16', 'Drama');.sp.fi.PPIn the context of \fBINSERT\fR, entries of a \fBVALUES\fR listcan be DEFAULT to indicate that the column defaultshould be used here instead of specifying a value:.sp.nfINSERT INTO films VALUES    ('UA502', 'Bananas', 105, DEFAULT, 'Comedy', '82 minutes'),    ('T_601', 'Yojimbo', 106, DEFAULT, 'Drama', DEFAULT);.sp.fi.PP\fBVALUES\fR can also be used where a sub-\fBSELECT\fR mightbe written, for example in a FROM clause:.sp.nfSELECT 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;.sp.fiNote that an AS clause is required when \fBVALUES\fRis used in a FROM clause, just as is true for\fBSELECT\fR. It is not required that the AS clausespecify names for all the columns, but it's good practice to do so.(The default column names for \fBVALUES\fR are column1,column2, etc in PostgreSQL, butthese names might be different in other database systems.).PPWhen \fBVALUES\fR is used in \fBINSERT\fR, the values are allautomatically coerced to the data type of the corresponding destinationcolumn. When it's used in other contexts, it may be necessary to specifythe correct data type. If the entries are all quoted literal constants,coercing the first is sufficient to determine the assumed type for all:.sp.nfSELECT * FROM machinesWHERE ip_address IN (VALUES('192.168.0.1'::inet), ('192.168.0.10'), ('192.168.1.43'));.sp.fi.sp.RS.B "Tip:"For simple IN tests, it's better to rely on thelist-of-scalars form of IN than to write a \fBVALUES\fRquery as shown above. The list of scalars method requires less writingand is often more efficient..RE.sp.SH "COMPATIBILITY".PP\fBVALUES\fR conforms to the SQL standard, except thatLIMIT and OFFSET arePostgreSQL extensions..SH "SEE ALSO"INSERT [\fBinsert\fR(7)], SELECT [\fBselect\fR(l)]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -