Thread: array constructor can't construct empty array
Hello I have function CREATE FUNCTION foo(date, date, INTEGER[]) RETURNS INTEGER Array and array's functions works fine, but I need call this function with empty array. I can't use array constructor for empty array. When I call function foo with e.a. ,I get syntax error. I can call with '{}'. What is coorect style? Thank You Pavel Stehule
Pavel Stehule wrote: > Hello > > I have function > > CREATE FUNCTION foo(date, date, INTEGER[]) RETURNS INTEGER > > Array and array's functions works fine, but I need call this function > with empty array. I can't use array constructor for empty array. When > I call function foo with e.a. ,I get syntax error. I can call with '{}'. Are you running 7.4beta? -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001+ If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania19073
On Mon, 1 Sep 2003, Bruce Momjian wrote: > Pavel Stehule wrote: > > Hello > > > > I have function > > > > CREATE FUNCTION foo(date, date, INTEGER[]) RETURNS INTEGER > > > > Array and array's functions works fine, but I need call this function > > with empty array. I can't use array constructor for empty array. When > > I call function foo with e.a. ,I get syntax error. I can call with '{}'. > > Are you running 7.4beta? > I am sorry, yes, of course :->, testdb=> SELECT version(); version ---------------------------------------------------------------------------PostgreSQL 7.4beta1 on i586-pc-linux-gnu, compiledby GCC gcc (GCC) 3.2.2 (1 řádka) >
Pavel Stehule wrote: >>>CREATE FUNCTION foo(date, date, INTEGER[]) RETURNS INTEGER >>> >>>Array and array's functions works fine, but I need call this function >>>with empty array. I can't use array constructor for empty array. When >>>I call function foo with e.a. ,I get syntax error. I can call with '{}'. >> >>Are you running 7.4beta? >> > > I am sorry, yes, of course :->, > testdb=> SELECT version(); > version > --------------------------------------------------------------------------- > PostgreSQL 7.4beta1 on i586-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.2 You haven't shown us your function or how you're trying to call it. In any case, works here: regression=# CREATE FUNCTION foo(INTEGER[], INTEGER) RETURNS INTEGER AS 'select ss.f[1] from (select $1 || $2 as f) as ss' language sql; CREATE FUNCTION regression=# select foo('{}'::int4[], 3); foo ----- 3 (1 row) Joe
Pavel Stehule <stehule@kix.fsv.cvut.cz> writes: > Array and array's functions works fine, but I need call this function > with empty array. I can't use array constructor for empty array. Yeah. We have not figured out how to assign a type to "ARRAY[]". You can do something like '{}'::integer[], however. regards, tom lane
On Mon, 1 Sep 2003, jconway wrote: > > You haven't shown us your function or how you're trying to call it. In > any case, works here: > > regression=# CREATE FUNCTION foo(INTEGER[], INTEGER) RETURNS INTEGER AS > 'select ss.f[1] from (select $1 || $2 as f) as ss' language sql; > CREATE FUNCTION > regression=# select foo('{}'::int4[], 3); > foo > ----- > 3 > (1 row) > > Joe I didn't show my function, because this function is unimportant. Header of my function was important. My question was about using array constructor ARRAY. Is possible construct empty array via this constructor? . For example I can select foo('{}'::int4[]) -- ok select foo('{}') -- ok too but select foo(array[]) -- syntax error, my function can by like Function FirstDay(date, integer[]) returns date as ' declare s; begin s := $1; loop if extract(dow from s) = ANY($2) then s := s + 1; else return s; end if end loop end' language plpgsq; Sometime I need call this function with empty array. That is all. Regards Pavel Stehule
> I can > select foo('{}'::int4[]) -- ok > select foo('{}') -- ok too > but > select foo(array[]) -- syntax error, > > my function can by like Correct -- you cannot use the ARRAY constructor empty. If you need an empty array, use '{}'. Search the archives for previous discussions on this topic during the June/July timeframe. This might change for 7.5, but don't count on it (at least not yet). Joe