next up previous contents index
Next: C Language Interface (LIBPQ) Up: PostgreSQL: Introduction and Concepts Previous: Summary

  
Programming Interfaces

 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.

 
Table: Interface summary
Interface Language Processing Advantages
LIBPQ  C compiled native interface
LIBPGEASY  C compiled simplified C
ECPG  C compiled ANSI embedded SQL C
LIBPQ++  C++ compiled object-oriented C
ODBC  ODBC compiled application connectivity
JDBC  Java both portability
PERL  Perl interpreted text processing
PGTCLSH TCL/TK  interpreted interfacing, windowing
PYTHON  Python interpreted object-oriented
PHP  HTML  interpreted dynamic Web pages


These language interfaces allow applications to pass queries to POSTGRESQL and receive results. The compiled languages execute more quickly, but are more difficult to program than the interpreted ones.

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 [*].


 


next up previous contents index
Next: C Language Interface (LIBPQ) Up: PostgreSQL: Introduction and Concepts Previous: Summary
Bruce Momjian
2001-05-09