0

I am using PostgreSQL 18.0 and I have written a function with default parameters which inserts movie into the table. However, when I add the argument which must be added, it gives error:

SQL Error [42725]: ERROR: function new_movie(text) is not unique Hint: Could not choose a best candidate function. You might need to add explicit type casts. Position: 16

Error position: line: 237 pos: 15

My function definition is something like this:

CREATE OR REPLACE FUNCTION new_movie (m_title text, r_year int DEFAULT EXTRACT(YEAR FROM CURRENT_DATE)::int, l_name text DEFAULT 'Klingon'::text)
RETURNS int
LANGUAGE plpgsql
AS $$

And I have tried to test it with this, but it did not work.

SELECT *
FROM new_movie('Silent Patient'::text);

SELECT *
FROM new_movie('Silent Patient');

How can I fix this problem?

3
  • 2
    The error function new_movie(text) is not unique is telling you the problem. Postgres allows you to overload functions. In psql do \df new_movie to see how many versions of that function you have and what their signatures are. Also see here CREATE FUNCTION section Overloading for example that possibly applies to your situation, in particular as relates to DEFAULT. Commented 15 hours ago
  • Oh, I did not know that. I checked it as you said and fixed the problem. Thank you so much. Commented 14 hours ago
  • About the thread closure here: the problem is reproducible and not caused by typos. It should be linked to any of the threads popping up in SO search for [postgres] function "is not unique". Commented 3 hours ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.