File: tutorial-populate.html

package info (click to toggle)
pgadmin3 1.4.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 29,796 kB
  • ctags: 10,758
  • sloc: cpp: 55,356; sh: 6,164; ansic: 1,520; makefile: 576; sql: 482; xml: 100; perl: 18
file content (75 lines) | stat: -rw-r--r-- 3,433 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>2.4.Populating a Table With Rows</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="tutorial-sql.html" title="Chapter2.The SQL Language">
<link rel="prev" href="tutorial-table.html" title="2.3.Creating a New Table">
<link rel="next" href="tutorial-select.html" title="2.5.Querying a Table">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="tutorial-populate"></a>2.4.Populating a Table With Rows</h2></div></div></div>
<a name="id568226"></a><p>    The <code class="command">INSERT</code> statement is used to populate a table  with
    rows:

</p>
<pre class="programlisting">INSERT INTO weather VALUES ('San Francisco', 46, 50, 0.25, '1994-11-27');</pre>
<p>

    Note that all data types use rather obvious input formats.
    Constants that are not simple numeric values usually must be
    surrounded by single quotes (<code class="literal">'</code>), as in the example.
    The
    <code class="type">date</code> type is actually quite flexible in what it
    accepts, but for this tutorial we will stick to the unambiguous
    format shown here.
   </p>
<p>    The <code class="type">point</code> type requires a coordinate pair as input,
    as shown here:
</p>
<pre class="programlisting">INSERT INTO cities VALUES ('San Francisco', '(-194.0, 53.0)');</pre>
<p>
   </p>
<p>    The syntax used so far requires you to remember the order of the
    columns.  An alternative syntax allows you to list the columns
    explicitly:
</p>
<pre class="programlisting">INSERT INTO weather (city, temp_lo, temp_hi, prcp, date)
    VALUES ('San Francisco', 43, 57, 0.0, '1994-11-29');</pre>
<p>
    You can list the columns in a different order if you wish or
    even omit some columns, e.g., if the precipitation is unknown:
</p>
<pre class="programlisting">INSERT INTO weather (date, city, temp_hi, temp_lo)
    VALUES ('1994-11-29', 'Hayward', 54, 37);</pre>
<p>
    Many developers consider explicitly listing the columns better
    style than relying on the order implicitly.
   </p>
<p>    Please enter all the commands shown above so you have some data to
    work with in the following sections.
   </p>
<p>    <a name="id568319"></a>

    You could also have used <code class="command">COPY</code> to load large
    amounts of data from flat-text files.  This is usually faster
    because the <code class="command">COPY</code> command is optimized for this
    application while allowing less flexibility than
    <code class="command">INSERT</code>.  An example would be:

</p>
<pre class="programlisting">COPY weather FROM '/home/user/weather.txt';</pre>
<p>

    where the file name for the source file must be available to the
    backend server machine, not the client, since the backend server
    reads the file directly.  You can read more about the
    <code class="command">COPY</code> command in <a href="sql-copy.html">COPY</a>.
   </p>
</div></body>
</html>