Skip site navigation (1) Skip section navigation (2)

Re: [INTERFACES] question on accessing PostgreSQL with C

From: James Thompson <jamest(at)math(dot)ksu(dot)edu>
To: hoelc <hoelc(at)pd(dot)jaring(dot)my>
Cc: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] question on accessing PostgreSQL with C
Date: 1999-02-07 01:16:14
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
On Sun, 7 Feb 1999, hoelc wrote:

> (2)  How to put variables into the SQL?
>         I use C program to access PostgreSQL with libpq, and use PQexec(
> ) to send the query. One of the failed example of mine,

I'd recommend using ecpg that comes with postgresql in the place of libpq
direct.  It is IMHO orders of magnitude easier than libpg alone.  The
syntax follows the same as Oracle's Pro*C so you can pretty much use any
of their manuals and get a working program.  I found an on-line copy of
the Pro*c manual at

With it you end up with something like the following in your code

    exec sql
      insert into customer(id,name_first,name_middle,name_last,company,
      values (:id,:name_first, :name_middle, :name_last,

the names preceeded by : are c variables.  The ecpg preprocessor replaces
this easily readable code with much nastier looking c code that does what
you require.

The author of the code is very responsive to few problem reports I have
sent him and has sent patches, or workarounds to me usually within 24

In the few cases you can't figure out a way to make something happen using
ecpg I believe you can mix the libpg and ecpg code in the same program.
The only place I could see a need for this is when you'd need the
functionality given by Pro*C's Dynamic SQL which ecpg doesn't yet support,
but I think its in the works.

You can find examples of ecpg code in the source tree

> (3)  How to check who are the users in PostgreSQL system?

select * from pg_user;

James Thompson    138 Cardwell Hall  Manhattan, Ks   66506    785-532-0561 
Kansas State University                          Department of Mathematics

In response to


pgsql-interfaces by date

Next:From: Dinesh PatilDate: 1999-02-07 01:42:29
Subject: help on libpq
Previous:From: hoelcDate: 1999-02-07 00:45:22
Subject: question on accessing PostgreSQL with C

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group