INSERT

Name

INSERT  --  Inserts new rows into a table テーブルに新しい行を挿入する。

Synopsis

INSERT INTO table [ ( column [, ...] ) ]
    { VALUES ( expression [, ...] ) | SELECT query }
  

入力

table

The name of an existing table.

既存のテーブルの名前。

column

The name of a column in table.

table 内のカラム名。

expression

A valid expression or value to assign to column.

column に代入す る有効な式または値。

query

A valid query. Refer to the SELECT statement for a further description of valid arguments.

有効な問い合わせ。有効な引数に関するより詳細な説明については SELECT 文を参照して下さい。

出力

INSERT oid 1

Message returned if only one row was inserted. oid is the numeric OID of the inserted row.

行が 1 つだけ挿入された場合に返されるメッセージ。 oid は挿入された行のOID 値です。

INSERT 0 #

Message returned if more than one rows were inserted. # is the number of rows inserted.

1 つ以上の行が挿入された場合に返されるメッセージ。 # は 挿入された行数です。

説明

INSERT allows one to insert new rows into a table. One can insert a single row at time or several rows as a result of a query. The columns in the target list may be listed in any order. In every column not present in the target list will be inserted the default value, if column has not a declared default value it will be assumed as NULL. If the expression for each column is not of the correct data type, automatic type coercion will be attempted.

INSERT を使用して、テーブルに新しい行を挿入するこ とができます。1 度に 1 つの行を挿入することも、問い合わせの結果として 複数の行を挿入することもできます。対象リスト内のカラムはどのような順番 でも指定できます。対象リストに無いカラムには、全てデフォルト値が挿入さ れます。カラムにデフォルト値が宣言されていない場合は、デフォルト値が NULL であるものとします。各カラムの式が正確なデータ型で無い場合は、自 動的に型の強制が行なわれます。

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.

テーブルに追加するためには、そのテーブルに INSERT 権限を持っていな ければいけません。同様に、WHERE 句で指定したテーブル全てについて SELECT 権限を持っていなければなりません。

使用法

Insert a single row into table films:

films テーブルに 1 つの行を挿入します。

INSERT INTO films VALUES
    ('UA502','Bananas',105,'1971-07-13','Comedy',INTERVAL '82 minute');
   

In this second example the column date_prod is omitted and therefore it will have the default value of NULL:

2 番目の例では、date_prod カラムを省略していま す。そのため、そこにはデフォルト値 NULL が入ります。

INSERT INTO films (code, title, did, date_prod, kind)
    VALUES ('T_601', 'Yojimbo', 106, DATE '1961-06-16', '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:

distributors テーブルに1つの行を挿入します。 name カラムだけが指定されていることに注目し て下さい。このため、did カラムにはそのデフォ ルト値が代入されることになります。

INSERT INTO distributors (name) VALUES ('British Lion');
   

Insert several rows into table films from table tmp:

tmp テーブルから films テーブルに複数の行を 挿入します。

INSERT INTO films SELECT * FROM tmp;
   

Insert into arrays (refer to The PostgreSQL User's Guide for further information about arrays):

配列に挿入します。(配列に関するより詳細な情報については PostgreSQL ユーザガイド を参照して下さい。)


-- Create an empty 3x3 gameboard for noughts-and-crosses
-- (all of these queries create the same board attribute)
-- 三目並べ用の空の 3x3 のゲーム盤を作成します。
-- (以下の問い合わせは全て同じ属性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,'{{,,},{,,},{,,}}');
   

互換性

SQL92

INSERT is fully compatible with SQL92. Possible limitations in features of the query clause are documented for the SELECT statement.

INSERTSQL92 と完全に互 換性があります。query 句の機能については制限があり、これについては SELECT 文に関する文書 にて記述します。