|Prev||Chapter 7. Managing a Database||Next|
Once you have constructed a database, you can access it by:
running the Postgres terminal monitor programs (e.g. psql) which allows you to interactively enter, edit, and execute SQL commands.
writing a C program using the LIBPQ subroutine library. This allows you to submit SQL commands from C and get answers and status messages back to your program. This interface is discussed further in section ??.
% psql mydbYou will be greeted with the following message:
Welcome to the POSTGRESQL interactive sql monitor: Please read the file COPYRIGHT for copyright terms of POSTGRESQL type \? for help on slash commands type \q to quit type \g or terminate with semicolon to execute query You are currently connected to the database: template1 mydb=>
This prompt indicates that the terminal monitor is listening to you and that you can type SQL queries into a workspace maintained by the terminal monitor. The psql program responds to escape codes that begin with the backslash character, “\” For example, you can get help on the syntax of various Postgres SQL commands by typing:
mydb=> \hOnce you have finished entering your queries into the workspace, you can pass the contents of the workspace to the Postgres server by typing:
mydb=> \gThis tells the server to process the query. If you terminate your query with a semicolon, the “\g” is not necessary. psql will automatically process semicolon terminated queries. To read queries from a file, say myFile, instead of entering them interactively, type:
mydb=> \i fileNameTo get out of psql and return to UNIX, type
mydb=> \qand psql will quit and return you to your command shell. (For more escape codes, type \h at the monitor prompt.) White space (i.e., spaces, tabs and newlines) may be used freely in SQL queries. Single-line comments are denoted by “--”. Everything after the dashes up to the end of the line is ignored. Multiple-line comments, and comments within a line, are denoted by “/* ... */”
|Alternate Database Locations||Up||Destroying a Database|
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.