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






Mon, 1 Sep 2003 17:18:13 +0200 (CEST)
Pavel Stehule <stehule@kix.fsv.cvut.cz>
array constructor can't construct  empty array
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, Pennsylvania 19073

Mon, 1 Sep 2003 12:58:40 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: array constructor can't construct  empty array

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, compiled by GCC gcc (GCC) 3.2.2
(1 ďż˝ďż˝dka)


> 


Mon, 1 Sep 2003 19:39:06 +0200 (CEST)
Pavel Stehule <stehule@kix.fsv.cvut.cz>
Re: array constructor can't construct  empty array
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




Mon, 01 Sep 2003 12:18:49 -0700
jconway <mail@joeconway.com>
Re: array constructor can't construct  empty array
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

Mon, 01 Sep 2003 17:15:19 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: array constructor can't construct empty array 
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



Tue, 2 Sep 2003 07:29:38 +0200 (CEST)
Pavel Stehule <stehule@kix.fsv.cvut.cz>
Re: array constructor can't construct  empty array
> 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



Mon, 01 Sep 2003 22:34:34 -0700
Joe Conway <mail@joeconway.com>
Re: array constructor can't construct  empty array