简体   繁体   中英

Query error while working with PL/pgSQL arrays

I have this function:

create or replace function insert_aereo( aereo_type[] ) returns text as $$
begin
   return 'ok';
end
$$ language plpgsql;

and this is the parameter type that I created:

create type aereo_type as (codice int, modello varchar, marca varchar);

Then I call my function:

select insert_aereo('{123, "ciao", "pippo"}');

but I get this error:

ERROR:  function insert_aereo(unknown) is not unique at character 8
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.
STATEMENT:  select insert_aereo('{123, "ciao", "pippo"}');
ERROR:  function insert_aereo(unknown) is not unique
LINE 1: select insert_aereo('{123, "ciao", "pippo"}');
               ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.

How can I fix it? What am I doing wrong?

You are using a bad format for composed types:

The correct format is:

'{"(123, ciao, pippo)", "(...)"}

see: http://www.postgresql.org/docs/8.4/interactive/rowtypes.html

or ARRAY[(1,'ciao','pippo')]::t[]

Pavel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM