Table of Contents
insert -- insert tuples to a relation
insert into classname
[(att.expr-1 [,att_expr.i] )]
{values (expression1 [,expression-i]
) |
select expression1 [,expression-i]
[from from-list] [where qual]
Insert adds instances that satisfy the qualification, qual,
to classname. Classname must be the name of an existing class. The target
list specifies the values of the fields to be appended to classname. That
is, each att_expr specifies a field (either an attribute name or an attribute
name plus an array specification) to which the corresponding expression
should be assigned. The fields in the target list may be listed in any
order. Fields of the result class which do not appear in the target list
default to NULL. If the expression for each field is not of the correct
data type, automatic type coercion will be attempted.
An array initialization
may take exactly one of the following forms: --
-- Specify a lower and upper
index for each dimension
--
att_name[lIndex-1:uIndex-1]..[lIndex-i:uIndex-i]
= array_str
--
--Specify only the upper index for each dimension
--(each
lower index defaults to 1)
--
att_name[uIndex-1]..[uIndex-i] = array_str
--
--Use the upper index bounds as specified within array_str
--(each lower
index defaults to 1)
--
att_name = array_str
where each lIndex or uIndex
is an integer constant and array_str is an array constant (see pgintro(1)
).
If the user does not specify any array bounds (as in the third form)
then Postgres will attempt to deduce the actual array bounds from the
contents of array_str.
If the user does specify explicit array bounds
(as in the first and second forms) then the array may be initialized partly
or fully using a C-like syntax for array initialization. However, the
uninitialized array elements will contain garbage.
You must have write
or append access to a class in order to append to it, as well as read
access on any class whose values are read in the target list or qualification
(see change acl(l)
).
--
--Make a new employee Jones work for Smith
--
insert into emp
select newemp.name, newemp.salary,
"Smith", 1990-newemp.age
from newemp
where name = "Jones"
--
--Insert into newemp class to newemp
--
insert into newemp
select * from newemp1
--
--Create an empty 3x3
gameboard for noughts-and-crosses
--(all of these queries create the same
board attribute)
--
insert into tictactoe (game, board[1:3][1:3])
values(1,'{{"","",""},{},{"",""}}')
insert into tictactoe (game, board[3][3])
values (2,'{}')
insert into tictactoe (game, board)
values (3,'{{,,},{,,},{,,}}')
create table(l)
, create type(l)
, update(l)
, select(l)
Table of Contents