OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / doc / postgresql / html / tutorial-accessdb.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Accessing a Database</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
9 REV="MADE"
10 HREF="mailto:pgsql-docs@postgresql.org"><LINK
11 REL="HOME"
12 TITLE="PostgreSQL 7.4.1 Documentation"
13 HREF="index.html"><LINK
14 REL="UP"
15 TITLE="Getting Started"
16 HREF="tutorial-start.html"><LINK
17 REL="PREVIOUS"
18 TITLE="Creating a Database"
19 HREF="tutorial-createdb.html"><LINK
20 REL="NEXT"
21 TITLE="The SQL Language"
22 HREF="tutorial-sql.html"><LINK
23 REL="STYLESHEET"
24 TYPE="text/css"
25 HREF="stylesheet.css"><META
26 NAME="creation"
27 CONTENT="2003-12-22T03:48:47"></HEAD
28 ><BODY
29 CLASS="SECT1"
30 ><DIV
31 CLASS="NAVHEADER"
32 ><TABLE
33 SUMMARY="Header navigation table"
34 WIDTH="100%"
35 BORDER="0"
36 CELLPADDING="0"
37 CELLSPACING="0"
38 ><TR
39 ><TH
40 COLSPAN="5"
41 ALIGN="center"
42 VALIGN="bottom"
43 >PostgreSQL 7.4.1 Documentation</TH
44 ></TR
45 ><TR
46 ><TD
47 WIDTH="10%"
48 ALIGN="left"
49 VALIGN="top"
50 ><A
51 HREF="tutorial-createdb.html"
52 ACCESSKEY="P"
53 >Prev</A
54 ></TD
55 ><TD
56 WIDTH="10%"
57 ALIGN="left"
58 VALIGN="top"
59 ><A
60 HREF="tutorial-start.html"
61 >Fast Backward</A
62 ></TD
63 ><TD
64 WIDTH="60%"
65 ALIGN="center"
66 VALIGN="bottom"
67 >Chapter 1. Getting Started</TD
68 ><TD
69 WIDTH="10%"
70 ALIGN="right"
71 VALIGN="top"
72 ><A
73 HREF="tutorial-start.html"
74 >Fast Forward</A
75 ></TD
76 ><TD
77 WIDTH="10%"
78 ALIGN="right"
79 VALIGN="top"
80 ><A
81 HREF="tutorial-sql.html"
82 ACCESSKEY="N"
83 >Next</A
84 ></TD
85 ></TR
86 ></TABLE
87 ><HR
88 ALIGN="LEFT"
89 WIDTH="100%"></DIV
90 ><DIV
91 CLASS="SECT1"
92 ><H1
93 CLASS="SECT1"
94 ><A
95 NAME="TUTORIAL-ACCESSDB"
96 >1.4. Accessing a Database</A
97 ></H1
98 ><A
99 NAME="AEN478"
100 ></A
101 ><P
102 >    Once you have created a database, you can access it by:
103
104     <P
105 ></P
106 ></P><UL
107 COMPACT="COMPACT"
108 ><LI
109 STYLE="list-style-type: disc"
110 ><P
111 >       Running the <SPAN
112 CLASS="PRODUCTNAME"
113 >PostgreSQL</SPAN
114 > interactive
115        terminal program, called <SPAN
116 CLASS="APPLICATION"
117 ><I
118 CLASS="FIRSTTERM"
119 >psql</I
120 ></SPAN
121 >, which allows you
122        to interactively enter, edit, and execute
123        <ACRONYM
124 CLASS="ACRONYM"
125 >SQL</ACRONYM
126 > commands.
127       </P
128 ></LI
129 ><LI
130 STYLE="list-style-type: disc"
131 ><P
132 >       Using an existing graphical frontend tool like
133        <SPAN
134 CLASS="APPLICATION"
135 >PgAccess</SPAN
136 > or an office suite with
137        <ACRONYM
138 CLASS="ACRONYM"
139 >ODBC</ACRONYM
140 > support to create and manipulate a
141        database.  These possibilities are not covered in this
142        tutorial.
143       </P
144 ></LI
145 ><LI
146 STYLE="list-style-type: disc"
147 ><P
148 >       Writing a custom application, using one of the several
149        available language bindings.  These possibilities are discussed
150        further in <A
151 HREF="client-interfaces.html"
152 >Part IV</A
153 >.
154       </P
155 ></LI
156 ></UL
157 ><P>
158
159     You probably want to start up <TT
160 CLASS="COMMAND"
161 >psql</TT
162 >, to try out
163     the examples in this tutorial.  It can be activated for the
164     <TT
165 CLASS="LITERAL"
166 >mydb</TT
167 > database by typing the command:
168 </P><PRE
169 CLASS="SCREEN"
170 ><SAMP
171 CLASS="PROMPT"
172 >$</SAMP
173 > <KBD
174 CLASS="USERINPUT"
175 >psql mydb</KBD
176 ></PRE
177 ><P>
178     If you leave off the database name then it will default to your
179     user account name.  You already discovered this scheme in the
180     previous section.
181    </P
182 ><P
183 >    In <TT
184 CLASS="COMMAND"
185 >psql</TT
186 >, you will be greeted with the following
187     message:
188 </P><PRE
189 CLASS="SCREEN"
190 >Welcome to psql 7.4.1, the PostgreSQL interactive terminal.
191  
192 Type:  \copyright for distribution terms
193        \h for help with SQL commands
194        \? for help on internal slash commands
195        \g or terminate with semicolon to execute query
196        \q to quit
197  
198 mydb=&gt;</PRE
199 ><P>
200     <A
201 NAME="AEN503"
202 ></A
203 >
204     The last line could also be
205 </P><PRE
206 CLASS="SCREEN"
207 >mydb=#</PRE
208 ><P>
209     That would mean you are a database superuser, which is most likely
210     the case if you installed <SPAN
211 CLASS="PRODUCTNAME"
212 >PostgreSQL</SPAN
213 >
214     yourself.  Being a superuser means that you are not subject to
215     access controls.  For the purpose of this tutorial this is not of
216     importance.
217    </P
218 ><P
219 >    If you have encountered problems starting <TT
220 CLASS="COMMAND"
221 >psql</TT
222 >
223     then go back to the previous section.  The diagnostics of
224     <TT
225 CLASS="COMMAND"
226 >psql</TT
227 > and <TT
228 CLASS="COMMAND"
229 >createdb</TT
230 > are
231     similar, and if the latter worked the former should work as well.
232    </P
233 ><P
234 >    The last line printed out by <TT
235 CLASS="COMMAND"
236 >psql</TT
237 > is the
238     prompt, and it indicates that <TT
239 CLASS="COMMAND"
240 >psql</TT
241 > is listening
242     to you and that you can type <ACRONYM
243 CLASS="ACRONYM"
244 >SQL</ACRONYM
245 > queries into a
246     work space maintained by <TT
247 CLASS="COMMAND"
248 >psql</TT
249 >.  Try out these
250     commands:
251     <A
252 NAME="AEN516"
253 ></A
254 >
255 </P><PRE
256 CLASS="SCREEN"
257 ><SAMP
258 CLASS="PROMPT"
259 >mydb=&gt;</SAMP
260 > <KBD
261 CLASS="USERINPUT"
262 >SELECT version();</KBD
263 >
264                             version
265 ----------------------------------------------------------------
266  PostgreSQL 7.4.1 on i586-pc-linux-gnu, compiled by GCC 2.96
267 (1 row)
268
269 <SAMP
270 CLASS="PROMPT"
271 >mydb=&gt;</SAMP
272 > <KBD
273 CLASS="USERINPUT"
274 >SELECT current_date;</KBD
275 >
276     date
277 ------------
278  2002-08-31
279 (1 row)
280
281 <SAMP
282 CLASS="PROMPT"
283 >mydb=&gt;</SAMP
284 > <KBD
285 CLASS="USERINPUT"
286 >SELECT 2 + 2;</KBD
287 >
288  ?column?
289 ----------
290         4
291 (1 row)</PRE
292 ><P>
293    </P
294 ><P
295 >    The <TT
296 CLASS="COMMAND"
297 >psql</TT
298 > program has a number of internal
299     commands that are not SQL commands.  They begin with the backslash
300     character, <SPAN
301 CLASS="QUOTE"
302 >"<TT
303 CLASS="LITERAL"
304 >\</TT
305 >"</SPAN
306 >.  Some of these
307     commands were listed in the welcome message.  For example,
308     you can get help on the syntax of various
309     <SPAN
310 CLASS="PRODUCTNAME"
311 >PostgreSQL</SPAN
312 > <ACRONYM
313 CLASS="ACRONYM"
314 >SQL</ACRONYM
315 >
316     commands by typing:
317 </P><PRE
318 CLASS="SCREEN"
319 ><SAMP
320 CLASS="PROMPT"
321 >mydb=&gt;</SAMP
322 > <KBD
323 CLASS="USERINPUT"
324 >\h</KBD
325 ></PRE
326 ><P>
327    </P
328 ><P
329 >    To get out of <TT
330 CLASS="COMMAND"
331 >psql</TT
332 >, type
333 </P><PRE
334 CLASS="SCREEN"
335 ><SAMP
336 CLASS="PROMPT"
337 >mydb=&gt;</SAMP
338 > <KBD
339 CLASS="USERINPUT"
340 >\q</KBD
341 ></PRE
342 ><P>
343     and <TT
344 CLASS="COMMAND"
345 >psql</TT
346 > will quit and return you to your
347     command shell. (For more internal commands, type
348     <TT
349 CLASS="LITERAL"
350 >\?</TT
351 > at the <TT
352 CLASS="COMMAND"
353 >psql</TT
354 > prompt.)  The
355     full capabilities of <TT
356 CLASS="COMMAND"
357 >psql</TT
358 > are documented in
359     <A
360 HREF="app-psql.html"
361 ><SPAN
362 CLASS="APPLICATION"
363 >psql</SPAN
364 ></A
365 >.  If <SPAN
366 CLASS="PRODUCTNAME"
367 >PostgreSQL</SPAN
368 > is
369     installed correctly you can also type <TT
370 CLASS="LITERAL"
371 >man psql</TT
372 >
373     at the operating system shell prompt to see the documentation.  In
374     this tutorial we will not use these features explicitly, but you
375     can use them yourself when you see fit.
376    </P
377 ></DIV
378 ><DIV
379 CLASS="NAVFOOTER"
380 ><HR
381 ALIGN="LEFT"
382 WIDTH="100%"><TABLE
383 SUMMARY="Footer navigation table"
384 WIDTH="100%"
385 BORDER="0"
386 CELLPADDING="0"
387 CELLSPACING="0"
388 ><TR
389 ><TD
390 WIDTH="33%"
391 ALIGN="left"
392 VALIGN="top"
393 ><A
394 HREF="tutorial-createdb.html"
395 ACCESSKEY="P"
396 >Prev</A
397 ></TD
398 ><TD
399 WIDTH="34%"
400 ALIGN="center"
401 VALIGN="top"
402 ><A
403 HREF="index.html"
404 ACCESSKEY="H"
405 >Home</A
406 ></TD
407 ><TD
408 WIDTH="33%"
409 ALIGN="right"
410 VALIGN="top"
411 ><A
412 HREF="tutorial-sql.html"
413 ACCESSKEY="N"
414 >Next</A
415 ></TD
416 ></TR
417 ><TR
418 ><TD
419 WIDTH="33%"
420 ALIGN="left"
421 VALIGN="top"
422 >Creating a Database</TD
423 ><TD
424 WIDTH="34%"
425 ALIGN="center"
426 VALIGN="top"
427 ><A
428 HREF="tutorial-start.html"
429 ACCESSKEY="U"
430 >Up</A
431 ></TD
432 ><TD
433 WIDTH="33%"
434 ALIGN="right"
435 VALIGN="top"
436 >The <ACRONYM
437 CLASS="ACRONYM"
438 >SQL</ACRONYM
439 > Language</TD
440 ></TR
441 ></TABLE
442 ></DIV
443 ></BODY
444 ></HTML
445 >