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

Handling data in libpq

From: am(at)fx(dot)ro
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Handling data in libpq
Date: 2002-10-19 10:23:52
Message-ID: 20021019132352.A419@coto (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
Hello everyone!

I have written a C program that:
- displays in a tabular form the data in a table
- allows inserts,deletes,updates, and user-defined filters('enter a query')
- uses libpq and ncurses.

The program is rather inefficient right now : 
- In order to fetch the data, i call:  
     RecordSet = PQexec(conn,"select FIELD1,...,FIELDn,OID from TBL");
     nRecords  = PQntuples(RecordSet);

- when i need a specific tuple, i call :
     PQgetvalue(RecordSet,crtRecord,field);   for each field

I'm looking for a new approach regarding fetching the data.
Usage of cursors is probably the path to follow. I would be deeply 
grateful to anyone who would share a bit of his/her experience:

- i assume the table has 50000 tuples
- what is better:  to fetch one tuple at one time, or to fetch
  a certain number of tuples (let's say 100).
- if i fetch 100 tuples, PQntuples returns 100? how do i know how
  many rows has the table?  
- i have the impression that keeping track of the tuple's index i
  nside the RecordSet and the index inside the whole table is quite 
  tricky, but manageable. How do you guys handle this kind of situations?
- are there more examples that use cursors, except the ones in
  docs ( in the libpq chapter )?
Adrian Maier

In response to


pgsql-interfaces by date

Next:From: Jeroen T. VermeulenDate: 2002-10-19 11:01:36
Subject: Re: Handling data in libpq
Previous:From: Jeroen T. VermeulenDate: 2002-10-18 14:23:08
Subject: Re: PgDatabase, on heap construction results in SIGSEGV.

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