Database Reference
In-Depth Information
ECPG DECLARE sections
While writing a .pgc program, we need to declare sections to write an SQL
command. All SQL variables that will be used will need to be declared between
the BEGIN and END DECLARE section as follows:
EXEC SQL BEGIN DECLARE SECTION;
/* Declare SQL Variables */
EXEC SQL END DECLARE SECTION;
Connection using ECPG
The CONNECT command is used to connect to the PostgreSQL server. Its syntax is
as follows:
EXEC SQL CONNECT TO target [AS connection-name] [USER user-name];
Let's consider the parameters of the preceding syntax:
target : The target PostgreSQL system includes information about the host
system, port information, connection options and database name as shown:
[tcp/unix]:postgresql://hostname [:port]/dbname[?options]
For example, if we want to connect a local instance of PostgreSQL using tcp ,
we will use the following target:
tcp:postgresql://127.0.01:5432/testdb
connection-name : This is the name of the connection. In some cases, the
program needs to make multiple connections with the database. Therefore,
this connection parameter is used to identify the connection. This is an
optional parameter, as in some cases the program does not need to have
multiple connections with the database.
user : This option is used to specify the username and the password and can
be in multiple formats such as the following:
EXEC SQL CONNECT TO postgres USER username / password;
EXEC SQL CONNECT TO postgres USER username IDENTIFIED BY
password;
EXEC SQL CONNECT TO postgres USER username USING password;
 
Search WWH ::




Custom Search