Re: How do I create an array?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe Conway <mail(at)joeconway(dot)com>
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 14:26:36
Message-ID: 12000.1044541596@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joe Conway <mail(at)joeconway(dot)com> writes:
> 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);

Yeah, that's what I was referring to by a "bespoke function". You'd
need one for every datatype; plus an entry in pg_proc for every number
of arguments you want to support (and it won't scale past MAX_FUNC_ARGS).
Doesn't seem like the avenue to a general solution.

This morning I was musing about overloading the CAST syntax to allow
array construction, along the lines of

CAST((x,y,z+2) AS float8[])

Perhaps multidimensional arrays could be done like this

CAST(((a11,a12,a13), (a21,a22,a23)) AS float8[])

But there are other ways you could imagine doing it, too.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-02-06 14:31:02 Re: COPY with fk's slow
Previous Message Nigel J. Andrews 2003-02-06 14:25:19 Re: how to determine OID of the row I just inserted???