diff --git a/doc/src/sgml/ref/create_table_as.sgml b/doc/src/sgml/ref/create_table_as.sgml index a93989586acee701928cbbc236248c33c30083d4..47c5829f153776ee72c88175607dc34e51a0f93f 100644 --- a/doc/src/sgml/ref/create_table_as.sgml +++ b/doc/src/sgml/ref/create_table_as.sgml @@ -1,5 +1,5 @@ @@ -15,7 +15,7 @@ Postgres documentation CREATE TABLE AS - Creates a new table + Creates a new table from the results of a SELECT @@ -41,7 +41,7 @@ CREATE [ TEMPORARY | TEMP ] TABLE table [ (TEMPORARY or TEMP - If specified, the table is created only for this session, and is + If specified, the table is created only within this session, and is automatically dropped on session exit. Existing permanent tables with the same name are not visible (in this session) while the temporary table exists. @@ -55,7 +55,10 @@ CREATE [ TEMPORARY | TEMP ] TABLE table [ (table - The name of a new table to be created. + The name of the new table to be created. + This table must not already exist. However, a temporary table + can be created that has the same name as an existing permanent + table. @@ -76,8 +79,9 @@ CREATE [ TEMPORARY | TEMP ] TABLE table [ (select_clause - A valid query statement. Refer to SELECT for a description of the - allowed syntax. + A valid query statement. Refer to + + for a description of the allowed syntax. @@ -92,27 +96,47 @@ CREATE [ TEMPORARY | TEMP ] TABLE table [ ( Outputs + - Refer to CREATE TABLE - and SELECT for a summary of possible output - messages. + Refer to + + and + + for a summary of possible output messages. - 1998-09-22 + 2001-03-20 Description - CREATE TABLE AS enables a table to be created - from the contents of an existing table. - It is functionally equivalent to + CREATE TABLE AS creates a table and fills it + with data computed by a SELECT command. The + table columns have the names and datatypes associated with the + output columns of the SELECT (except that you + can override the SELECT column names by giving + an explicit list of column names). + + + + CREATE TABLE AS bears some resemblance to creating + a view, but it is really quite different: it creates a new table and + evaluates the SELECT just once to fill the new table + initially. The new table will not track subsequent changes to + the source tables of the SELECT. In contrast, + a view re-evaluates the given SELECT whenever queried. + + + + This command is functionally equivalent to , - but with perhaps a more direct syntax. + but it is preferred since it is less likely to be confused with + other uses of the SELECT ... INTO syntax. diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml index 26bc9bdf4efcfa7257bb67bf653ef47b19a0b497..f971359d8b2cb42dd5fae4731da0092389ea9f0e 100644 --- a/doc/src/sgml/ref/select.sgml +++ b/doc/src/sgml/ref/select.sgml @@ -1,5 +1,5 @@ @@ -15,7 +15,7 @@ Postgres documentation SELECT - Retrieve rows from a table or view. + Retrieves rows from a table or view @@ -24,7 +24,6 @@ Postgres documentation SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] * | expression [ AS output_name ] [, ...] - [ INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table ] [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] @@ -80,39 +79,6 @@ where from_item can be: - - TEMPORARY - TEMP - - - If TEMPORARY or TEMP is specified, - the output table is created unique to this session, and is - automatically dropped on session exit. - - - - - - new_table - - - If the INTO TABLE clause is specified, the result of the - query will be stored in a new table with the indicated - name, rather than being returned to the client. - The target table (new_table) will - be created automatically and must not exist before this command. - Refer to SELECT INTO for more information. - - - - The CREATE TABLE AS statement will also - create a new table from a SELECT query. - - - - - - from_item diff --git a/doc/src/sgml/ref/select_into.sgml b/doc/src/sgml/ref/select_into.sgml index c80395de80328fa480f716b3c9f6e2d25d52ef71..50d2780a6dcbd8d5e9380aacb960ceb765e6e771 100644 --- a/doc/src/sgml/ref/select_into.sgml +++ b/doc/src/sgml/ref/select_into.sgml @@ -1,5 +1,5 @@ @@ -15,7 +15,7 @@ Postgres documentation SELECT INTO - Create a new table from an existing table or view + Creates a new table from the results of a SELECT @@ -48,51 +48,112 @@ where from_item can be: - 1998-09-22 + 2001-03-20 Inputs + + + + + TEMPORARY + TEMP + + + If TEMPORARY or TEMP is specified, + the output table is created only within this session, and is + automatically dropped on session exit. + Existing permanent tables with the same name are not visible + (in this session) while the temporary table exists. + Any indexes created on a temporary table are automatically + temporary as well. + + + + + + new_table + + + The name of the new table to be created. + This table must not already exist. However, a temporary table + can be created that has the same name as an existing permanent + table. + + + + + + - All input fields are described in detail for + All other inputs are described in detail for . - 1998-09-22 + 2001-03-20 Outputs + - All output fields are described in detail for - . + Refer to + + and + + for a summary of possible output messages. - 1998-09-22 + 2001-03-20 Description + - SELECT INTO creates a new table from the results - of a query. Typically, this - query draws data from an existing table, but any SQL query is allowed. + 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 datatypes associated with the + output columns of the SELECT. - is functionally equivalent to the SELECT INTO command. + is functionally equivalent to SELECT INTO. + CREATE TABLE AS is the recommended syntax, since + SELECT INTO is not standard. In fact, this form of + SELECT INTO is not available in PL/pgSQL or ecpg, + because they interpret the INTO clause differently. + + + + Compatibility + + + + SQL92 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 PL/pgSQL and ecpg. + The Postgres 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.) + +