pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Henk Jan Barendregt <henkjan@barendregt.xs4all.nl>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-interfaces@postgreSQL.org
Subject: Re: [INTERFACES] [libpq] Return value of int
Date: Sun, 02 May 1999 16:30:30 +0000
Message-ID: <372C7DA6.3399D65@barendregt.xs4all.nl> (raw)
References: <13408.925661516@sss.pgh.pa.us>

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



view thread (4+ messages)  latest in thread

Message-ID: <372C7DA6.3399D65@barendregt.xs4all.nl>
Permalink:  ../372C7DA6.3399D65@barendregt.xs4all.nl/
Also on:    postgresql.org/message-id/372C7DA6.3399D65@barendregt.xs4all.nl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: henkjan@barendregt.xs4all.nl, tgl@sss.pgh.pa.us
  Subject: Re: [INTERFACES] [libpq] Return value of int
  In-Reply-To: <372C7DA6.3399D65@barendregt.xs4all.nl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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