LIBNAME Statement for the PostgreSQL Engine

Overview

This section describes the LIBNAME statement that SAS/ACCESS Interface to PostgreSQL supports. For general information about this feature, see LIBNAME Statement for Relational Databases.

Here is the LIBNAME statement syntax for accessing PostgreSQL.

LIBNAME libref postgres <connection-options> <LIBNAME-options>;

For general information about the LIBNAME statement that is not specific to SAS/ACCESS, see LIBNAME Statement in SAS Global Statements: Reference.

Arguments

libref

specifies any SAS name that serves as an alias to associate SAS with a database, schema, server, or group of tables and views.

postgres

specifies the SAS/ACCESS engine name for the PostgreSQL interface.

connection-options

provide connection information and control how SAS manages the timing and concurrence of the connection to the DBMS. Here is how these options are specified.

Note: All of these connection options (preceding the table of PostgreSQL LIBNAME statement options) are valid when used in the CONNECT statement with the SQL procedure.
SERVER=<'>PostgreSQL-server-name<'>

specifies the server name or IP address of the PostgreSQL server to which you want to connect. This server accesses the database that contains the tables and views that you want to access. If the server name contains spaces or nonalphanumeric characters, you must enclose it in quotation marks.

DATABASE=<'>PostgreSQL-database-name<'>

specifies the name of the database on the PostgreSQL server that contains the tables and views that you want to access. If the database name contains spaces or nonalphanumeric characters, you must enclose it in quotation marks.

Alias: DB=

PORT=port

specifies the port number that is used to connect to the specified PostgreSQL server.

Default: 5432

USER=<'>PostgreSQL-user-name<'>

specifies the PostgreSQL user name (also called the user ID) that you use to connect to your database. If the user name contains spaces or nonalphanumeric characters, you must enclose it in quotation marks.

Alias: UID=

PASSWORD=<'>PostgreSQL-password<'>

specifies the password that is associated with your PostgreSQL user name. If the password contains spaces or nonalphanumeric characters, you must enclose it in quotation marks.

Alias: PASS=, PW=, PWD=

DSN=<'>PostgreSQL-data-source<'>

specifies the configured PostgreSQL ODBC data source to which you want to connect. Use this option if you have existing PostgreSQL ODBC data sources that are configured on your client. This method requires additional setup—either through the Administrator control panel on Windows platforms or through the odbc.ini file or a similarly named configuration file on UNIX platforms. So it is recommended that you use this connection method only if you have existing, functioning data sources that have been specified.

COMPLETE=<'>CLI-connection-string<'>

specifies connection information for your database for PCs only. Separate multiple options with a semicolon. When a successful connection is made, the complete connection string is returned in the SYSDBMSG macro variable. If you do not specify enough correct connection options, you are prompted with a dialog box that displays the values from the COMPLETE= connection string. You can edit any field before you connect to the database. See your PostgreSQL documentation for more details.

This option is not available on UNIX platforms.

PROMPT=<'>PostgreSQL-connection-options<'>

specifies connection options for your database. Separate multiple options with a semicolon. When connection succeeds, the complete connection string is returned in the SYSDBMSG macro variable. PROMPT= does not immediately try to connect to the DBMS. Instead, it displays a dialog box in SAS Display Manager that contains the values that you entered in the PROMPT= connection string. You can edit values or enter additional values in any field before you connect to the database.

Restriction: This option is not available on UNIX platforms.

NOPROMPT=<'>PostgreSQL-connection-options<'>

specifies connection options for your database. Separate multiple options with a semicolon. If you do not specify enough correct connection options, an error is returned. No dialog box is displayed to help you with the connection string.

LIBNAME-options

specify how SAS processes DBMS objects. Some LIBNAME options can enhance performance, and others determine locking or naming behavior. The following table describes the LIBNAME options for SAS/ACCESS Interface to PostgreSQL with the applicable default values. This table also identifies LIBNAME options that are valid in the CONNECT statement in the SQL procedure. For details, see LIBNAME Options for Relational Databases.

SAS/ACCESS LIBNAME Options for PostgreSQL

Option

Default Value

Valid in CONNECT

ACCESS=

none

AUTHDOMAIN=

none

AUTOCOMMIT=

NO

BL_WRITEBUFF=

10000

CLIENT_ENCODING=

current SAS session encoding

CONNECTION=

SHAREDREAD

CONNECTION_GROUP=

none

CONOPTS=

none

CURSOR_TYPE=

DYNAMIC

DBCLIENT_MAX_BYTES=

matches the maximum number of bytes per single character of the SAS session encoding

DBCOMMIT=

1000 (when inserting rows), 0 (when updating rows)

DBCONINIT=

none

DBCONTERM=

none

DBCREATE_TABLE_OPTS=

none

DBGEN_NAME=

DBMS

DBINDEX=

NO

DBLIBINIT=

none

DBLIBTERM=

none

DBMAX_TEXT=

1024

DBMSTEMP=

NO

DBNULLKEYS=

YES

DBPROMPT=

NO

DEFER=

NO

DELETE_MULT_ROWS=

NO

DIRECT_EXE=

none

DIRECT_SQL=

YES

IGNORE_READ_ONLY_ COLUMNS=

NO

INSERT_SQL=

YES

INSERTBUFF=

1

KEYSET_SIZE=

0

LOGIN_TIMEOUT=

0

MULTI_DATASRC_OPT=

NONE

POST_STMT_OPTS=

none

PRESERVE_COL_NAMES=

NO

PRESERVE_TAB_NAMES=

NO

QUALIFIER=

none

QUERY_TIMEOUT=

0

QUOTE_CHAR=

none

READ_ISOLATION_LEVEL=

RC (see Locking in the PostgreSQL Interface)

READ_LOCK_TYPE=

ROW

READBUFF=

0

REREAD_EXPOSURE=

NO

SCHEMA=

none

SPOOL=

YES

SQL_FUNCTIONS=

none

SQL_FUNCTIONS_COPY=

none

SQLGENERATION=

none

SSLMODE=

prefer

STRINGDATES=

NO

SUB_CHAR=

none

TRACE=

NO

TRACEFILE=

none

UPDATE_ISOLATION_LEVEL=

RC (see Locking in the PostgreSQL Interface

UPDATE_LOCK_TYPE=

ROW

UTILCONN_TRANSIENT=

NO

LIBNAME Statement Examples for PostgreSQL

In this example, SERVER=, DATABASE=, USER=, and PASSWORD= are connection options. No DSN style is specified. This is the default method, which is recommended.

libname A1 postgres server=mysrv1 port=5432 
   user=myusr1 password='mypwd1' database=mydb1;

This example requires that you specify a DSN style.

libname B1 postgres dsn=ptgtest user=myusr1 password=mypwd1;
Last updated: February 3, 2026