SELECT INTO 中文man頁面
NAME
SELECT INTO - 從一個查詢的結(jié)果中創(chuàng)建一個新表
SYNOPSIS
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] * | expression [ AS output_name ] [, ...] INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ] [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start ] [ FOR UPDATE [ OF tablename [, ...] ] ]
DESCRIPTION 描述
SELECT INTO 從一個查詢的計算結(jié)果中創(chuàng)建一個新表。 數(shù)據(jù)并不返回給客戶端,這一點和普通的 SELECT 不同。 新表的字段具有和 SELECT 的輸出字段相關(guān)聯(lián)(相同)的名字和數(shù)據(jù)類型。
PARAMETERS 參數(shù)
- TEMPORARY 或 TEMP
如果聲明了這個關(guān)鍵字,那么該表是作為一個臨時表創(chuàng)建的。 請參考 CREATE TABLE [create_table(7)] 獲取細節(jié)。- new_table
要創(chuàng)建的表的表名(可以有模式修飾)。
所有其它輸入的域都在 SELECT [select(7)] 中有詳細描述。
NOTES 注意
CREATE TABLE AS [create_table_as(7)] 的作用和 SELECT INTO 相同。 我們建議使用 CREATE TABLE AS 語法, 因為 SELECT INTO 不是標準語法。 實際上,這種類型的 SELECT INTO 是不能在 ECPG 或者 PL/pgSQL 中使用的, 因為它們對 INTO 子句的解釋是不同的。
COMPATIBILITY 兼容性
SQL 標準用 SELECT ... INTO 表示選取數(shù)值到一個宿主程序的標量變量中, 而不是創(chuàng)建一個新表。這種用法實際上就是在 ECPG (參閱 Chapter 29)和PL/pgSQL (Chapter 35)里的用途。 PostgreSQL 用 SELECT INTO 代表創(chuàng)建表的意思是歷史原因。 在新代碼里我們***使用 CREATE TABLE AS 實現(xiàn)這個目地。 (CREATE TABLE AS 也不是標準,但至少它出現(xiàn)混淆的機會少一些。)
#p#
NAME
SELECT INTO - create a new table from the results of a query
SYNOPSIS
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] * | expression [ AS output_name ] [, ...] INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ] [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start ] [ FOR UPDATE [ OF tablename [, ...] ] ]
DESCRIPTION
SELECT INTO creates a new table and fills it with data computed by a query. The data is not returned to the client, as it is with a normal SELECT. The new table's columns have the names and data types associated with the output columns of the SELECT.
PARAMETERS
- TEMPORARY or TEMP
- If specified, the table is created as a temporary table. Refer to CREATE TABLE [create_table(7)] for details.
- new_table
- The name (optionally schema-qualified) of the table to be created.
All other parameters are described in detail under SELECT [select(7)].
NOTES
CREATE TABLE AS [create_table_as(7)] is functionally equivalent to SELECT INTO. CREATE TABLE AS is the recommended syntax, since this form of SELECT INTO is not available in ECPG or PL/pgSQL, because they interpret the INTO clause differently.
COMPATIBILITY
The SQL standard uses SELECT ... INTO to represent selecting values into scalar variables of a host program, rather than creating a new table. This indeed is the usage found in ECPG and PL/pgSQL. The PostgreSQL usage of SELECT INTO to represent table creation is historical. It's best to use CREATE TABLE AS for this purpose in new code. (CREATE TABLE AS isn't standard either, but it's less likely to cause confusion.)