1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
12
TITLE="PostgreSQL 9.1beta1 Documentation"
13
HREF="index.html"><LINK
15
TITLE="Data Manipulation"
18
TITLE="Data Manipulation"
22
HREF="dml-update.html"><LINK
25
HREF="stylesheet.css"><META
26
HTTP-EQUIV="Content-Type"
27
CONTENT="text/html; charset=ISO-8859-1"><META
29
CONTENT="2011-04-27T21:20:33"></HEAD
35
SUMMARY="Header navigation table"
47
>PostgreSQL 9.1beta1 Documentation</A
56
TITLE="Data Manipulation"
66
TITLE="Data Manipulation"
74
>Chapter 6. Data Manipulation</TD
80
TITLE="Data Manipulation"
90
HREF="dml-update.html"
105
>6.1. Inserting Data</A
108
> When a table is created, it contains no data. The first thing to
109
do before a database can be of much use is to insert data. Data is
110
conceptually inserted one row at a time. Of course you can also
111
insert more than one row, but there is no way to insert less than
112
one row. Even if you know only some column values, a
113
complete row must be created.
116
> To create a new row, use the <A
117
HREF="sql-insert.html"
120
command. The command requires the
121
table name and column values. For
122
example, consider the products table from <A
127
CLASS="PROGRAMLISTING"
128
>CREATE TABLE products (
134
An example command to insert a row would be:
136
CLASS="PROGRAMLISTING"
137
>INSERT INTO products VALUES (1, 'Cheese', 9.99);</PRE
139
The data values are listed in the order in which the columns appear
140
in the table, separated by commas. Usually, the data values will
141
be literals (constants), but scalar expressions are also allowed.
144
> The above syntax has the drawback that you need to know the order
145
of the columns in the table. To avoid this you can also list the
146
columns explicitly. For example, both of the following commands
147
have the same effect as the one above:
149
CLASS="PROGRAMLISTING"
150
>INSERT INTO products (product_no, name, price) VALUES (1, 'Cheese', 9.99);
151
INSERT INTO products (name, price, product_no) VALUES ('Cheese', 9.99, 1);</PRE
153
Many users consider it good practice to always list the column
157
> If you don't have values for all the columns, you can omit some of
158
them. In that case, the columns will be filled with their default
161
CLASS="PROGRAMLISTING"
162
>INSERT INTO products (product_no, name) VALUES (1, 'Cheese');
163
INSERT INTO products VALUES (1, 'Cheese');</PRE
165
The second form is a <SPAN
169
extension. It fills the columns from the left with as many values
170
as are given, and the rest will be defaulted.
173
> For clarity, you can also request default values explicitly, for
174
individual columns or for the entire row:
176
CLASS="PROGRAMLISTING"
177
>INSERT INTO products (product_no, name, price) VALUES (1, 'Cheese', DEFAULT);
178
INSERT INTO products DEFAULT VALUES;</PRE
182
> You can insert multiple rows in a single command:
184
CLASS="PROGRAMLISTING"
185
>INSERT INTO products (product_no, name, price) VALUES
188
(3, 'Milk', 2.99);</PRE
198
> When inserting a lot of data at the same time, considering using
203
It is not as flexible as the <A
204
HREF="sql-insert.html"
207
command, but is more efficient. Refer
211
> for more information on improving
212
bulk loading performance.
222
SUMMARY="Footer navigation table"
251
HREF="dml-update.html"
261
>Data Manipulation</TD
b'\\ No newline at end of file'