Re: How do I create an array?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How do I create an array?
Дата
Msg-id 12999.1044549423@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: How do I create an array?  (Joe Conway <mail@joeconway.com>)
Список pgsql-general
Joe Conway <mail@joeconway.com> writes:
> It seems like you should be able to define the function:
> CREATE OR REPLACE FUNCTION array (any)
> RETURNS anyarray
> AS '$libdir/plr','array'
> LANGUAGE 'C' WITH (isstrict);

You could write that definition, but the implementation could be hard:
I don't think there's any way for the function to know what datatype
it's been passed.

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

>  From SQL99
> <array value expression> ::= <array value constructor>
>                             | <array concatenation>
>                             | <value expression primary>

Oh cool, I had not thought to look in SQL99.  Clearly we should lift
their syntax.

> and in section 6.4 SQL99 indicates that the array datatype should be derived
> from the datatype of its first element (again, not sure I'm reading the spec
> correctly):

Whether you are or not, I'd be inclined to ignore that and instead use
UNION's algorithm for deriving the union type.  Consider

    ARRAY [ 1, 1.1, 1.4e10 ]

You don't want it to type that as integer[], IMHO.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Arjen van der Meijden
Дата:
Сообщение: Re: password() function?
Следующее
От: James Hall
Дата:
Сообщение: Pg_dumpall problem[2]