Re: Proposal: new function array_init - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: Proposal: new function array_init
Date
Msg-id 162867790806041441y6b6ea65aw4a0f3b2d6fd390@mail.gmail.com
Whole thread Raw
In response to Re: Proposal: new function array_init  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Proposal: new function array_init  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
2008/6/4 Tom Lane <tgl@sss.pgh.pa.us>:
> "Pavel Stehule" <pavel.stehule@gmail.com> writes:
>> idealized code:
>
>> a = array_set(array[10,10]); // untyped null array
>> a[10,10] = 'text'; -- now array is typed
>
> And how did you declare 'a'?  This seems like a solution in search of a
> problem.
>
you have true - problem is in assignment

next question:

when I declare function only for anyelement, I can't simply create text array

CREATE OR REPLACE FUNCTION array_fill(dv anyelement, dims int[])
RETURNS anyarray
AS 'MODULE_PATHNAME', 'array_fill'
LANGUAGE C IMMUTABLE;

postgres=# select array_fill(1,array[4,4]);               array_fill
-------------------------------------------{{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}}
(1 row)

Time: 1,369 ms
postgres=# select array_fill('p',array[4,4]);
ERROR:  could not determine polymorphic type because input has type "unknown"

I can use hack:
CREATE OR REPLACE FUNCTION array_fill(dv text, dims int[])
RETURNS text[]
AS 'MODULE_PATHNAME', 'array_fill'
LANGUAGE C IMMUTABLE;

postgres=# select array_fill('p',array[4,4]);               array_fill
-------------------------------------------{{p,p,p,p},{p,p,p,p},{p,p,p,p},{p,p,p,p}}
(1 row)


what do you thing about it?

regards
Pavel Stehule

>                        regards, tom lane
>


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Proposal: new function array_init
Next
From: "BRUSSER Michael"
Date:
Subject: Re: Overhauling GUCS