From: Achilleus Mantzios <achill@matrix.gatewaynet.com>
To: David Durst <ddurst@larubber.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Passing arrays
Date: Fri, 14 Feb 2003 11:17:31 -0200 (GMT+2)
Message-ID: <Pine.LNX.4.44.0302141108510.21195-200000@matrix.gatewaynet.com> (raw)
In-Reply-To: <42097.216.86.192.34.1045213079.squirrel@www.la-rubber.com>
On Fri, 14 Feb 2003, David Durst wrote:
> This is slightly off the original topic but related.
>
> Is there any function or way I can easily find the size of the passed array?
You can always parse
SELECT array_dims(<your array column here>)::text from <your table here> ;
Or write a function using the macros in
/usr/local/pgsql/include/server/utils/array.h
to get the size of each dimension.
(i have attached a simple function that does that)
> > On Fri, 14 Feb 2003, Michael Weaver wrote:
> >
> >>
> >>
> >> > -----Original Message-----
> >> > From: Stephan Szabo [mailto:sszabo@megazone23.bigpanda.com]
> >> > Sent: Friday, 14 February 2003 12:58 PM
> >> > To: Michael Weaver
> >> > Cc: 'pgsql-novice@postgresql.org'; 'pgsql-sql@postgresql.org'
> >> > Subject: Re: [SQL] Passing arrays
> >> >
> >> >
> >> >
> >> > On Fri, 14 Feb 2003, Michael Weaver wrote:
> >> >
> >> > > How do you get an array of elements to be passed to a
> >> > stored proc such that
> >> > > you can use the array in a SELECT statement in the WHERE clause
> >> > > - e.g. WHERE field IN (array) etc...
> >> >
> >> > A straight WHERE field IN (array) doesn't work. That's attempting
> >> to compare the field directly to the array as a whole (which is
> >> > why you get
> >> > the particular error you do.
> >>
> >> I've got around this limitation using strings, but I do find it
> >> suprising, that Postgres handles arrays this way.
> >> Searching an array in an WHERE IN clause would be a useful task.
> >> (namely for passing arrays of values between stored functions)
> >>
> >> Ok it could be confusing, but I think a number of other DBs employ it
> >> to good effect.
> >>
> >> I'll take a look at the array extension in contrib - it sounds useful.
> >
> > Also check out contrib/intarray and its indexing capabilites
> > if you have 1 dimensional integer arrays.
> >
> >>
> >> Thanks.
> >>
> >
> > ==================================================================
> > Achilleus Mantzios
> > S/W Engineer
> > IT dept
> > Dynacom Tankers Mngmt
> > Nikis 4, Glyfada
> > Athens 16610
> > Greece
> > tel: +30-10-8981112
> > fax: +30-10-8981877
> > email: achill@matrix.gatewaynet.com
> > mantzios@softlab.ece.ntua.gr
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>
>
>
> ---------------------------(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-10-8981112
fax: +30-10-8981877
email: achill@matrix.gatewaynet.com
mantzios@softlab.ece.ntua.gr
Attachments:arrlevel.c (text/plain, 777B) download
#include "postgres.h"
#include "access/gist.h"
#include "access/itup.h"
#include "access/rtree.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
PG_FUNCTION_INFO_V1(level);
Datum level(PG_FUNCTION_ARGS);
Datum level(PG_FUNCTION_ARGS)
{
int nitems,ndim,*dim;
char *p=0;
ArrayType *intarray = (ArrayType *) DatumGetPointer(PG_GETARG_DATUM(0));
if (intarray == 0 ) return (int4) 0;
intarray = DatumGetArrayTypeP(PointerGetDatum(intarray));
if (intarray == 0 ) return (int4) 0;
p = ARR_DATA_PTR(intarray);
if (p == 0) return (int4) 0;
ndim = ARR_NDIM(intarray);
dim = ARR_DIMS(intarray);
nitems = ArrayGetNItems(ndim, dim);
return (int4) nitems;
}
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-sql@postgresql.org
Cc: achill@matrix.gatewaynet.com, ddurst@larubber.com
Subject: Re: Passing arrays
In-Reply-To: <Pine.LNX.4.44.0302141108510.21195-200000@matrix.gatewaynet.com>
* 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