Re: How do I create an array? - Mailing list pgsql-general

From Tom Lane
Subject Re: How do I create an array?
Date
Msg-id 12000.1044541596@sss.pgh.pa.us
Whole thread Raw
In response to Re: How do I create an array?  (Joe Conway <mail@joeconway.com>)
Responses Re: How do I create an array?  (Joe Conway <mail@joeconway.com>)
List pgsql-general
Joe Conway <mail@joeconway.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

pgsql-general by date:

Previous
From: "Nigel J. Andrews"
Date:
Subject: Re: how to determine OID of the row I just inserted???
Next
From: Tom Lane
Date:
Subject: Re: COPY with fk's slow