Thread: How access to array component

How access to array component

From
Cristian Cappo
Date:
Hello  How access to especific array component
of an function with return type _varchar
  declaration of my function:
>>>  create or replace __function( int2, int2 ) returns _varchar ....
  now use the function in SQL and access to the element 1...
>>>  select __function(10::int2, 20::int2)[1]                  ^^^ parsing error.
  Thanks.


Cristian Cappo
-------------



Re: How access to array component

From
Joe Conway
Date:
Cristian Cappo wrote:
>  >>>  select __function(10::int2, 20::int2)[1]
>                       ^^^ parsing error.
> 

Try:

create or replace function foo(int2, int2 ) returns _varchar as '
select ''{1,2}''::_varchar
' language 'sql';

regression=# select (foo(10::int2, 20::int2))[1]; foo
----- 1
(1 row)

HTH,

Joe



Re: How access to array component

From
"Cristian Cappo A."
Date:
JoeTried, but...
>> select (foo(10::int2,20::int2))[1];>> ERROR:  parser: parse error at or near "[" at character 32
I'm using the version 7.3.3 

Thanks..
---

> Cristian Cappo wrote:
> >  >>>  select __function(10::int2, 20::int2)[1]
> >                       ^^^ parsing error.
> > 
> 
> Try:
> 
> create or replace function foo(int2, int2 ) returns _varchar as '
> select ''{1,2}''::_varchar
> ' language 'sql';
> 
> regression=# select (foo(10::int2, 20::int2))[1];
>   foo
> -----
>   1
> (1 row)
> 
> HTH,
> 
> Joe
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

------------------------------------
Cristian Cappo Araujo
Desarrollo de Proyectos - Direccion Tecnica
Centro Nacional de Computación
Universidad Nacional de Asunción

email: ccappo@cnc.una.py
tel. : 595-021-585550
fax  : 595-021-585619



Re: How access to array component

From
Joe Conway
Date:
Cristian Cappo A. wrote:
>  Tried, but...
>  >> select (foo(10::int2,20::int2))[1];
>  >> ERROR:  parser: parse error at or near "[" at character 32
> 
>  I'm using the version 7.3.3 

Sorry, it works on 7.4devel, so I thought it might on 7.3 as well. In 
any case, this works on 7.3.3:

test=# select f1[1] from (select foo(10::int2, 20::int2) as f1) as ss; f1
---- 1
(1 row)

HTH,

Joe



Re: How access to array component

From
"Cristian Cappo A."
Date:
Thanks Joe..

------
On 21 Jul 2003 at 22:09, Joe Conway wrote:

> Cristian Cappo A. wrote:
> >  Tried, but...
> >  >> select (foo(10::int2,20::int2))[1];
> >  >> ERROR:  parser: parse error at or near "[" at character 32
> > 
> >  I'm using the version 7.3.3 
> 
> Sorry, it works on 7.4devel, so I thought it might on 7.3 as well. In 
> any case, this works on 7.3.3:
> 
> test=# select f1[1] from (select foo(10::int2, 20::int2) as f1) as ss;
>   f1
> ----
>   1
> (1 row)
> 
> HTH,
> 
> Joe

------------------------------------
Cristian Cappo Araujo
Desarrollo de Proyectos - Direccion Tecnica
Centro Nacional de Computación
Universidad Nacional de Asunción

email: ccappo@cnc.una.py
tel. : 595-021-585550
fax  : 595-021-585619