Next: , Previous: GET DATA /TYPE=GNM/ODS, Up: GET DATA


9.4.2 Postgres Database Queries

     GET DATA /TYPE=PSQL
              /CONNECT={connection info}
              /SQL={query}
              [/ASSUMEDVARWIDTH=w]
              [/UNENCRYPTED]
              [/BSIZE=n].

The PSQL type is used to import data from a postgres database server. The server may be located locally or remotely. Variables are automatically created based on the table column names or the names specified in the SQL query. Postgres data types of high precision, will loose precision when imported into pspp. Not all the postgres data types are able to be represented in pspp. If a datum cannot be represented a warning will be issued and that datum will be set to SYSMIS.

The CONNECT subcommand is mandatory. It is a string specifying the parameters of the database server from which the data should be fetched. The format of the string is given in the postgres manual http://www.postgresql.org/docs/8.0/static/libpq.html#LIBPQ-CONNECT.

The SQL subcommand is mandatory. It must be a valid SQL string to retrieve data from the database.

The ASSUMEDVARWIDTH subcommand specifies the maximum width of string variables read from the database. If omitted, the default value is determined from the length of the string in the first value read for each variable.

The UNENCRYPTED subcommand allows data to be retrieved over an insecure connection. If the connection is not encrypted, and the UNENCRYPTED subcommand is not given, then an error will occur. Whether or not the connection is encrypted depends upon the underlying psql library and the capabilities of the database server.

The BSIZE subcommand serves only to optimise the speed of data transfer. It specifies an upper limit on number of cases to fetch from the database at once. The default value is 4096. If your SQL statement fetches a large number of cases but only a small number of variables, then the data transfer may be faster if you increase this value. Conversely, if the number of variables is large, or if the machine on which pspp is running has only a small amount of memory, then a smaller value will be better.

The following syntax is an example:

     GET DATA /TYPE=PSQL
          /CONNECT='host=example.com port=5432 dbname=product user=fred passwd=xxxx'
          /SQL='select * from manufacturer'.