Skip to Content
Practical PostgreSQL
book

Practical PostgreSQL

by Joshua D. Drake, John C. Worsley
January 2002
Intermediate to advanced
640 pages
16h 39m
English
O'Reilly Media, Inc.
Content preview from Practical PostgreSQL

Select Into

Construct a new table from the results of a SELECT.

Synopsis

SELECT [ ALL | DISTINCT [ ON ( distinct_expression [, ...] ) ] ]
    target_expression [ AS output_name ] [, ...]
    [ INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table ]
    [ FROM from_item [ { , | CROSS JOIN } ...] ]
    [ WHERE condition ]
    [ GROUP BY aggregate_expression [, ...] ]
    [ HAVING aggregate_condition [, ...] ]
    [ { UNION | INTERSECT | EXCEPT [ALL] } select ]
    [ ORDER BY order_expression [ ASC | DESC | USING operator ] [, ...] ]
    [ FOR UPDATE [ OF update_table [, ...] ] ]
    [ LIMIT { ALL | count } [ { OFFSET | , } start ] ]
from_item ::= { [ ONLY ] table_name [ * ]
                  [ [ AS ] from_alias [ ( column_alias_list ) ] ] |
                ( select ) [ [ AS ] alias [ ( column_alias_list ) ] ] |
                from_item [ NATURAL ] join_type from_item
                  [ ON ( join_condition ) | USING ( join_column_list ) ]
               }

join_type ::= [ INNER |
                LEFT  [ OUTER ] |
                RIGHT [ OUTER ] |
                FULL  [ OUTER ]
              ] JOIN

Parameters

Most SELECT INTO parameters are the same as for the SELECT command. The following two are the only parameters unique to SELECT INTO:

TEMPORARY, TEMP

The TEMPORARY (or TEMP) keyword indicates that the table is for temporary use; it will be destroyed when the session has ended.

new_table

The name of the new table created to hold the resulting rows of the query. This table will be created automatically and must not already exist before you execute this command.

Results

Refer to the reference entry titled “CREATE TABLE” and the reference entry titled “SELECT” for a list of possible ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PostgreSQL: Up and Running, 2nd Edition

PostgreSQL: Up and Running, 2nd Edition

Regina O. Obe, Leo S. Hsu
Learning PostgreSQL 11 - Third Edition

Learning PostgreSQL 11 - Third Edition

Christopher Travers, Andrey Volkov
Learn PostgreSQL

Learn PostgreSQL

Luca Ferrari, Enrico Pirozzi
PostgreSQL High Performance Cookbook

PostgreSQL High Performance Cookbook

Dinesh Kumar, Chitij Chauhan

Publisher Resources

ISBN: 9781449309770Supplemental ContentErrata Page