The INSERT statement is used to add rows to the table:
INSERT into Weather VALUES (' San Francisco ', 46, 50, 0.25, ' 1994-11-27 ');
Please note that all data types use a fairly straightforward input format. Constants that are not simple numeric values must be enclosed in single quotation marks ('), as in the example. The date type is actually quite flexible in the format that can be received, but in this tutorial we should stick to the format shown here.
The point type requires a coordinate pair as input, as follows:
INSERT into Cities VALUES (' San Francisco ', ' (-194.0, 53.0) ');
The syntax used so far requires you to remember the order of the fields. An optional syntax allows you to explicitly list the fields:
INSERT into weather (city, Temp_lo, Temp_hi, PRCP, date) VALUES (' San Francisco ', 43, 57, 0.0, ' 1994-11-29 ');
If you want, you can list the fields in a different order or omit certain fields, for example, we don't know the precipitation:
INSERT into weather (date, city, Temp_hi, Temp_lo) VALUES (' 1994-11-29 ', ' Hayward ', 54, 37);
Many developers think that it is better to explicitly list the fields than to rely on the implied order.
Please enter all the commands shown above so that you have the data available in subsequent sections.
You can also use COPY to load large amounts of data from a text file. This is usually faster because the COPY command is optimized for this type of application, but less flexible than INSERT . Like what:
COPY weather from '/home/user/weather.txt ';
The filename of the source file must be accessible to the backend server, not to the client, because the backend server reads the file directly. You can read more information about the copy command in copy .
For more information refer to http://www.infocool.net/PostgreSQL/index.htm
2.4. Adding rows to the PostgreSQL table