Re: [INTERFACES] [libpq] Return value of int

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Henk Jan Barendregt <henkjan(at)barendregt(dot)xs4all(dot)nl>
Cc: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] [libpq] Return value of int
Date: 1999-05-02 16:11:56
Message-ID: 13408.925661516@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Henk Jan Barendregt <henkjan(at)barendregt(dot)xs4all(dot)nl> writes:
> How can i use libpq to return an int value when i access an INT or INT4
> value

Use atoi() ... what comes out of libpq is a character string always.
It's up to you to convert it to whatever form you want it in.

Actually, if you are really intent on avoiding the conversion step
you can use a binary cursor and get the data in whatever the backend's
internal format is. However I can't recommend this. I've found by
measurement that the conversion time is insignificant compared to the
rest of the work involved in a query, even for expensive-to-convert
datatypes like DATETIME. And for that trivial savings you expend a
lot of programming effort: you have to know what the backend's internal
format *is*, and you have to be prepared to deal with cross-machine
compatibility issues (maybe the backend is running on a machine with
different endianness than your app is ... how will you even know?),
cross-Postgres-version changes in the internal representation, yadda
yadda. Much better to take the character string.

But if you insist on doing it the hard way, read about DECLARE CURSOR
and FETCH in the manual.

regards, tom lane

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Henk Jan Barendregt 1999-05-02 16:30:30 Re: [INTERFACES] [libpq] Return value of int
Previous Message Martin Skøtt 1999-05-02 13:28:35 Re: Auto incrementing Field