Re: How do I create an array?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How do I create an array?
Дата
Msg-id 12000.1044541596@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: How do I create an array?  (Joe Conway <mail@joeconway.com>)
Ответы Re: How do I create an array?
Список 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 по дате отправления:

Предыдущее
От: "Nigel J. Andrews"
Дата:
Сообщение: Re: how to determine OID of the row I just inserted???
Следующее
От: Tom Lane
Дата:
Сообщение: Re: COPY with fk's slow