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