pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feed[libpq] Return value of int
4+ messages / 3 participants
[nested] [flat]
* [libpq] Return value of int
@ 1999-05-02 09:32 Henk Jan Barendregt <henkjan@barendregt.xs4all.nl>
0 siblings, 1 reply; 4+ messages in thread
From: Henk Jan Barendregt @ 1999-05-02 09:32 UTC (permalink / raw)
To: pgsql-interfaces
Hello,
How can i use libpq to return an int value when i access an INT or INT4
value
For example :
result = PQexec (connection,"SELECT integervalue FROM integertable");
I have followed the example nr 3 in the pogrammers guide but i still get
a
char * when i use PQgetvalues
Thanks in advance,
Henk Jan Barendregt
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [INTERFACES] [libpq] Return value of int
@ 1999-05-02 16:11 Tom Lane <tgl@sss.pgh.pa.us>
parent: Henk Jan Barendregt <henkjan@barendregt.xs4all.nl>
0 siblings, 2 replies; 4+ messages in thread
From: Tom Lane @ 1999-05-02 16:11 UTC (permalink / raw)
To: Henk Jan Barendregt <henkjan@barendregt.xs4all.nl>; +Cc: pgsql-interfaces
Henk Jan Barendregt <henkjan@barendregt.xs4all.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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [INTERFACES] [libpq] Return value of int
@ 1999-05-02 16:30 Henk Jan Barendregt <henkjan@barendregt.xs4all.nl>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 4+ messages in thread
From: Henk Jan Barendregt @ 1999-05-02 16:30 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces
Tom Lane wrote:
>
> Henk Jan Barendregt <henkjan@barendregt.xs4all.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
Thanks a lot for the explanation. It is gave me some good reasons to
stay on
my path and convert the results to whatever i need.
Henk Jan
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [INTERFACES] [libpq] Return value of int
@ 1999-05-02 19:35 D'Arcy J.M. Cain <darcy@druid.net>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 4+ messages in thread
From: "D'Arcy" "J.M." Cain @ 1999-05-02 19:35 UTC (permalink / raw)
To: tgl@sss.pgh.pa.us; +Cc: pgsql-interfaces
Thus spake Tom Lane
> Henk Jan Barendregt <henkjan@barendregt.xs4all.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.
Regarding this, it would be nice if libpq had some official, documented
way of determining the type of the field. Currently I deal with this
in PyGreSQL by stealing some #defines from src/include/catalog/pg_type.h,
something that isn't normally available to application programmers. In
fact, maybe we just have to move those #defines into postgres.h or
something that is in the public include directory.
Just thinking out loud.
--
D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1999-05-02 19:35 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-05-02 09:32 [libpq] Return value of int Henk Jan Barendregt <henkjan@barendregt.xs4all.nl>
1999-05-02 16:11 ` Tom Lane <tgl@sss.pgh.pa.us>
1999-05-02 16:30 ` Henk Jan Barendregt <henkjan@barendregt.xs4all.nl>
1999-05-02 19:35 ` D'Arcy J.M. Cain <darcy@druid.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox