Psql is ideal for interactively entering SQL commands and for running automated scripts, but it is not ideal for writing applications. Fortunately, POSTGRESQL has interfaces for many programming languages. Programming languages include variables, functions, conditional evaluation, looping, and complex input/output routines, all of which are required for writing good applications.
Table shows the supported programming interfaces.
This chapter will show the same application using each of the interfaces listed
in Table . The application is a very simple one that
prompts the user for a United States state code and outputs the state name that
goes with the code. Figure shows the sample
application being run.
Enter a state code: AL
Alabama
For clarity, the text typed by the user appears in bold. The program displays
a prompt, the user types AL, and the program displays Alabama.
Although state codes are unique, the application is written to allow multiple
query return values. The application uses the statename table, which
is recreated in Figure .
test=> CREATE TABLE statename (code CHAR(2) PRIMARY KEY,
test(> name CHAR(30)
test(> );
CREATE
test=> INSERT INTO statename VALUES ('AL', 'Alabama');
INSERT 18934 1
test=> INSERT INTO statename VALUES ('AK', 'Alaska');
INSERT 18934 1
...
Additional information about POSTGRESQL interfaces is available in the Programmer's Manual mentioned in Appendix .