X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 30F81476178 for ; Thu, 27 Mar 2003 02:22:59 -0500 (EST) Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) by postgresql.org (Postfix) with ESMTP id AB71B475F34 for ; Thu, 27 Mar 2003 02:22:57 -0500 (EST) Received: from matrix.gatewaynet.com (matrix.gatewaynet.com [217.19.69.50] (may be forged)) by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h2RBaLIs014109; Thu, 27 Mar 2003 09:36:21 -0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id h2RBaF38014105; Thu, 27 Mar 2003 09:36:19 -0200 Date: Thu, 27 Mar 2003 09:36:15 -0200 (GMT+2) From: Achilleus Mantzios To: "G. Anthony Reina" Cc: Joe Conway , Subject: Re: How can I pass an array from PostgreSQL to C (libpq)? In-Reply-To: <519653832.1048700831@dell1.neurobio.pitt.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Status: No, hits=-37.8 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE,USER_AGENT_PINE autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/611 X-Sequence-Number: 12649 On Wed, 26 Mar 2003, G. Anthony Reina wrote: See contrib/intarray > Yes, in the past I had used binary cursor and things seemed to work fine. > However, recently when I ran the binary cursor stuff, the array ends up > getting shifted to the right one index. So what should be placed in > array_var[n] was getting placed in array var[n+1]. Plus, I was always a > little concerned with the binary cursor when going across platforms (e.g. > endianess, alignment). > > I ended up just writing a little script that parses the string for the > comma separators. That works fine, but wanted to see if others had more > elegant solutions. I'll take a look at the /utils directory you mentioned. > Perhaps there are functions that I'm not aware of (e.g. I didn't know there > was a built in function called array_dims that gives the array dimensions). > > -Tony > > > --On Wednesday, March 26, 2003 11:07 AM -0800 Joe Conway > wrote:r > > > > PQgetvalue is always going to give you the string representation of the > > field value *unless* you specify a binary cursor. In that case you'll get > > all requested fields in binary form, and it's your responsibility to deal > > with making sense of what you get. There are some backend macros and > > functions that can help you get at array values. Take a look at > > src/utils/adt/arrayfuncs.c and src/include/utils/array.h. You might want > > to read through contrib/array and/or contrib/intarray for examples. > > > > You could also consider writing your array manipulation code in a user > > defined C function and just return the end result to the libpq program. > > It's hard to know if this is an option without more detail on what you're > > trying to do. > > > > Joe > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) > -- ================================================================== Achilleus Mantzios S/W Engineer IT dept Dynacom Tankers Mngmt Nikis 4, Glyfada Athens 16610 Greece tel: +30-210-8981112 fax: +30-210-8981877 email: achill@matrix.gatewaynet.com mantzios@softlab.ece.ntua.gr