627Chapter 34PostgreSQLBecause a database is a mandatory argument to the interactive client and we don t want towork directly on one of our template databases, we ll start by creating a single database thatwe ll use for the rest of this chapter: createdb sampleThat s all there is to creating a new database, but of course, this is just a blank slate at thispoint a minimalist canvas based on the template database and on which we will paint astructure to our exacting specifications. Now we can use the interactive client to work with our database: psql sampleThis will open a copy of sampleand drop us at a prompt along with some instructions. Theprompt inside the interactive client is different from the shell prompt, which can help youdistinguish where you are exactly. This is especially useful on a Linux system where multipleshells open at one time is an everyday occurrence. The prompt will take the form=#, such that our prompt will look like: sample=# If you issue the ?command from this prompt, you ll get a very long list of everything youcan do from this prompt, exclusive of SQL specifics, which of course are also supported here. We can t offer exhaustive coverage here, but a few key commands are worth exploring. .The hcommand lists available help for all of the supported SQL constructs such asSELECT, DELETE, GRANT, and so on. .The dcommand, along with one of its accepted parameters, will display informationabout your database or specific objects in it. Of specific interest are dt, which will listall tables in the current database, and d
, which will show the structureof the specified table. .Hturns on HTML output, which is handy for exporting data quickly to the Web. In con- junction with the Tcommand you can customize the html output somewhat, and youcan use oto send it all to a file. Incidentally, you can call all of these options on the command line when starting psql. Simply substitute a hyphen for the slash and psqlwill execute the commands in sequenceand then exit. For even greater utility, you can group these commands in a text file and readthem in from the command line. Down to Real WorkLet s build a simple structure inside our sample database. This example is necessarily abbre- viated, but it is designed to give you a quick but useful familiarity with the Postgres and itsSQL syntax. If you have already exited from our previous example, get back in to the sampledatabase: psql sampleLet s start by defining a simple table to hold the names of some cartoons we really like: CREATE TABLE cartoons(id serial, cartoon varchar(30));
You want to have a cheap webhost for your apache application, then check apache web hosting services.
This entry was posted
on Tuesday, September 25th, 2007 at 5:06 pm and is filed under Domain.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.