PostgreSQL

Скачать в pdf «PostgreSQL»


1.    It creates a table called newfriend.


2.    It uses SELECT’s column labels to name the columns of the new table.


3.    It uses select’s column types as the column types of the new table.


test=> SELECT firstname, lastname, city, state test-> INTO    newfriend


test-> FROM    friend;


SELECT


test=> d newfriend


Table «newfriend»


Attribute | Type | Extra


————+———-+——-


firstname | char(15) | lastname | char(20) | city | char(15) | state | char(2) |


test=> SELECT * FROM newfriend ORDER BY firstname;


firstname


| lastname


| city


|


state


Dean


| Yeager


| Plymouth


|


MA


Dick


| Gleason


| Ocean City


|


nj


Ned


| Millstone


| Cedar Creek


|


MD


Sandy


| Gleason


| Ocean City


|


nj


Sandy


| Weber


| Boston


|


MA


Victor


| Tabor


| Williamsport


|


PA

(6 rows)


s.s. summary


Select…into essentially combines create table and select in a single statement. The AS clause can be used to change the column labels and thus control the column names in the new table. The other commands in the figure show the new table’s structure and contents.


Select…into tablename can also be written as create table tablename as select…. The preceding query can then be rewritten as create table newfriend AS selectfirstname, lastname, city, state from friend.

Скачать в pdf «PostgreSQL»