Received: from smtp3.xs4all.nl (smtp3.xs4all.nl [194.109.6.53]) by hub.org (8.9.3/8.9.3) with ESMTP id MAA66137 for ; Sun, 2 May 1999 12:27:37 -0400 (EDT) (envelope-from henkjan@barendregt.xs4all.nl) Received: from barendregt.xs4all.nl (root@barendregt.xs4all.nl [194.109.56.73]) by smtp3.xs4all.nl (8.8.8/8.8.8) with ESMTP id SAA12256; Sun, 2 May 1999 18:27:21 +0200 (CEST) Received: from barendregt.xs4all.nl (henkjan@localhost [127.0.0.1]) by barendregt.xs4all.nl (8.8.8/8.8.8) with ESMTP id SAA12873; Sun, 2 May 1999 18:30:31 +0200 Sender: henkjan@barendregt.xs4all.nl Message-ID: <372C7DA6.3399D65@barendregt.xs4all.nl> Date: Sun, 02 May 1999 16:30:30 +0000 From: Henk Jan Barendregt Organization: Barendregt Building co. X-Mailer: Mozilla 4.5 [en] (X11; I; Linux 2.0.36 i586) X-Accept-Language: nl, en MIME-Version: 1.0 To: Tom Lane CC: pgsql-interfaces@postgreSQL.org Subject: Re: [INTERFACES] [libpq] Return value of int References: <13408.925661516@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Tom Lane wrote: > > Henk Jan Barendregt 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