From 20aae3047fb6a04c7cd042873aefa5cba404cfa9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 26 Apr 2003 23:56:51 +0000 Subject: Editing of more reference pages. --- doc/src/sgml/ref/insert.sgml | 325 +++++++++++++++++++------------------------ 1 file changed, 143 insertions(+), 182 deletions(-) (limited to 'doc/src/sgml/ref/insert.sgml') diff --git a/doc/src/sgml/ref/insert.sgml b/doc/src/sgml/ref/insert.sgml index fa1f945068b..d2e29a87577 100644 --- a/doc/src/sgml/ref/insert.sgml +++ b/doc/src/sgml/ref/insert.sgml @@ -1,5 +1,5 @@ @@ -8,246 +8,207 @@ PostgreSQL documentation INSERT SQL - Language Statements + - - INSERT - - - create new rows in a table - + INSERT + create new rows in a table + - - 2000-08-08 - - + INSERT INTO table [ ( column [, ...] ) ] - { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) | SELECT query } - - - - - Inputs - - - - - - - table - - - The name (optionally schema-qualified) of an existing table. - - - - - - column - - - The name of a column in table. - - - - - - DEFAULT VALUES - - - All columns will be filled by null values or by values specified - when the table was created using DEFAULT clauses. - - - - - - expression - - - A valid expression or value to assign to column. - - - - - - DEFAULT - - - This column will be filled in by the column DEFAULT clause, or NULL if - a default is not available. - - - - - - query - - - A valid query. Refer to the SELECT statement for a further description - of valid arguments. - - - - - - - - - - Outputs - - - - - - -INSERT oid 1 - - - - Message returned if only one row was inserted. - oid - is the numeric OID of the inserted row. - - - - - -INSERT 0 # - - - - Message returned if more than one rows were inserted. - # - is the number of rows inserted. - - - - - - + { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) | query } + - - - Description - + + Description INSERT allows one to insert new rows into a table. One can insert a single row at a time or several rows as a result of a query. - The columns in the target list may be listed in any order. + The columns in the target list may be listed in any order. Each column not present in the target list will be inserted - using a default value, either a declared DEFAULT value - or NULL. PostgreSQL will reject the new - column if a NULL is inserted into a column declared NOT NULL. + using a default value, either a declared default value + or null. - If the expression for each column - is not of the correct data type, automatic type coercion will be - attempted. + If the expression for each column is not of the correct data type, + automatic type conversion will be attempted. - You must have insert privilege to a table in order to append - to it, as well as select privilege on any table specified - in a WHERE clause. + You must have INSERT privilege to a table in + order to insert into it. If you use the query clause to insert rows from a + query, you also need to have SELECT privilege on + any table used in the query. - - - Usage - + + Parameters + + + + table + + + The name (optionally schema-qualified) of an existing table. + + + + + + column + + + The name of a column in table. + + + + + + DEFAULT VALUES + + + All columns will be filled their default values. + + + + + + expression + + + An expression or value to assign to column. + + + + + + DEFAULT + + + This column will be filled with its default value. + + + + + + query + + + A query (SELECT statement) that supplies the + rows to be inserted. Refer to the SELECT + statement for a description of the syntax. + + + + + + + + Diagnostics + + + + INSERT oid 1 + + + Message returned if only one row was inserted. + oid is the + OID of the inserted row. + + + + + + INSERT 0 count + + + Message returned if more than one rows were inserted. + count is the number of rows inserted. + + + + + + + + Examples + Insert a single row into table films: - + INSERT INTO films VALUES - ('UA502','Bananas',105,'1971-07-13','Comedy',INTERVAL '82 minute'); - + ('UA502', 'Bananas', 105, '1971-07-13', 'Comedy', '82 minutes'); + - In this second example the last column len is - omitted and therefore it will have the default value of NULL: + In this second example, the last column len is + omitted and therefore it will have the default value of null: - + INSERT INTO films (code, title, did, date_prod, kind) - VALUES ('T_601', 'Yojimbo', 106, DATE '1961-06-16', 'Drama'); - + VALUES ('T_601', 'Yojimbo', 106, '1961-06-16', 'Drama'); + - In the third example, we use the DEFAULT values for the date columns - rather than specifying an entry. + The third example uses the DEFAULT clause for + the date columns rather than specifying a value: - + INSERT INTO films VALUES - ('UA502','Bananas',105,DEFAULT,'Comedy',INTERVAL '82 minute'); + ('UA502', 'Bananas', 105, DEFAULT, 'Comedy', '82 minutes'); INSERT INTO films (code, title, did, date_prod, kind) VALUES ('T_601', 'Yojimbo', 106, DEFAULT, 'Drama'); - - - - - Insert a single row into table distributors; note that - only column name is specified, so the omitted - column did will be assigned its default value: - - -INSERT INTO distributors (name) VALUES ('British Lion'); - + - Insert several rows into table films from table tmp: + This examples inserts several rows into table + films from table tmp: - + INSERT INTO films SELECT * FROM tmp; - + - Insert into arrays: + This example inserts into array columns: - + -- Create an empty 3x3 gameboard for noughts-and-crosses --- (all of these queries create the same board attribute) +-- (all of these commands create the same board) 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,'{{,,},{,,},{,,}}'); - + - - - Compatibility - - - - - SQL92 - - - INSERT is fully compatible with SQL92. - Possible limitations in features of the - query - clause are documented for - . - - + + Compatibility + + + INSERT conforms fully to the SQL standard. + Possible limitations of the query clause are documented under + . + -- cgit v1.2.3