By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,116 Members | 1,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,116 IT Pros & Developers. It's quick & easy.

array parameter in plpgsql function

P: 37
Hi team,

I am creating a function that would accept an array of integer as its parameter. I have a table where one of its column is declared as an array. This is an excerpt from the script that I was creating:

Expand|Select|Wrap|Line Numbers
  1. create or replace function insert_busshours(bigint, varchar, integer[]) returns integer as
  2. '
  3.     begin
  4.        insert into businesshours values ($1,$2,$3);
  5.        return ''0'';
  6.  
  7.     end;
  8. '
  9. language 'plpgsql';
This is how I called this script:

Expand|Select|Wrap|Line Numbers
  1. select insert_busshours (5,'tues','{10,23}');
Then I got the following error:
ERROR: function insert_busshours(integer, "unknown", "unknown") is not unique
HINT: Could not choose a best candidate function. You may need to add explicit type casts.


Can someone help me point out where the problem is? Thanks for your answers as always.
Jul 20 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 534
Postgresql supports function overloading, so I think while working on it you probably defined a similar function with the same name but slightly different argument types.
When you call this function the server cannot figure out which instance to invoke, hence the error.

Look at all functions with the name insert_busshours and drop everything you don't need.

If you don't have any tools you can do it at the psql prompt:
Expand|Select|Wrap|Line Numbers
  1. -- this command displays the basic info on given function 
  2. postgres=# \df  insert_busshours
  3. -- get more details with extended option
  4. postgres=# \df+  insert_busshours
  5.  
Jul 20 '07 #2

P: 37
hi michaelb,

Thank you very much!! It worked now. I am so happy to have you here in thescript. You've helped me a lot already. ^^
Jul 23 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.