From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Greg Stark <gsstark(at)mit(dot)edu>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: How do I create an array? |
Date: | 2003-02-06 05:51:28 |
Message-ID: | 3E41F7E0.7020003@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Tom Lane wrote:
> Also, I'll bet that Joe Conway's upcoming plr makes it just as easy as pie
> (once you learn R, anyway). But plain SQL and plpgsql don't really have
> much to fall back on to support such things.
>
You mean something like this?
create or replace function vec(float, float) returns _float8 as 'c(arg1,arg2)'
language 'plr';
select vec(1.23, 1.32);
vec
-------------
{1.23,1.32}
(1 row)
Actually, while I was at it I also wrote a C function called "array" which can
be declared to take as many arguments (to the max allowed) and return a
corresponding array. It is useful since R likes to work with arrays. E.g:
CREATE OR REPLACE FUNCTION array (float8, float8) RETURNS float8[] AS
'$libdir/plr','array' LANGUAGE 'C' WITH (isstrict);
regression=# select array(1.24,2.35);
array
-------------
{1.24,2.35}
(1 row)
CREATE OR REPLACE FUNCTION array (float8, float8, float8) RETURNS float8[] AS
'$libdir/plr','array' LANGUAGE 'C' WITH (isstrict);
regression=# select array(1.24,2.35,4.57);
array
------------------
{1.24,2.35,4.57}
(1 row)
I'm still working out the kinks with PL/R, and I've just started the
documentation, but it's pretty much feature complete, at least as far as the
first release goes.
Per previous discussion it won't be usable for trigger functions, and it
doesn't handle greater than 2d arrays as arguments or return types. But it
does allow scalar, 1d and 2d array, and composite type arguments. And it can
return scalar, 1d and 2d arrays, and composite types (i.e. supports table
functions).
I've been developing against cvs, but I tested today against 7.3.2 and it
passed its regression test. If you're feeling adventurous, let me know and
I'll send a copy directly.
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | Curt Sampson | 2003-02-06 06:37:46 | Re: Temporary and permanent tables with same name |
Previous Message | Tom Lane | 2003-02-06 05:30:03 | Re: databases limit |