array parameter in plpgsql function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • twinklyblue
    New Member
    • Jun 2007
    • 37

    #1

    array parameter in plpgsql function

    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:

    Code:
    create or replace function insert_busshours(bigint, varchar, integer[]) returns integer as
    '
    	begin
           insert into businesshours values ($1,$2,$3);
           return ''0'';
           
        end;
    '
    language 'plpgsql';
    This is how I called this script:

    Code:
    select insert_busshours (5,'tues','{10,23}');
    Then I got the following error:
    ERROR: function insert_busshour s(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.
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    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_busshour s and drop everything you don't need.

    If you don't have any tools you can do it at the psql prompt:
    [CODE=sql]
    -- this command displays the basic info on given function
    postgres=# \df insert_busshour s
    -- get more details with extended option
    postgres=# \df+ insert_busshour s
    [/CODE]

    Comment

    • twinklyblue
      New Member
      • Jun 2007
      • 37

      #3
      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. ^^

      Comment

      Working...