When I run this script:
CREATE OR REPLACE FUNCTION registeruser(character varying, character varying, money, character varying, character varying, date)
RETURNS void AS
$BODY$
BEGIN
INSERT INTO "Users"("Name", "Surnames", "Money", "Email", "Password", "UserType", "State", "BirthDate")
VALUES ($1,$2,$3,$4,$5,'Costumer','Active',$6);
END;
$BODY$ LANGUAGE plpgsql VOLATILE;
SELECT RegisterUser('Andrea','Gianchero',0,'[email protected]','rome','1960-04-12');
I get this error:
ERROR: function registeruser(unknown, unknown, integer, unknown, unknown, unknown) does not exist
LINE 1: SELECT RegisterUser('Andrea','Gianchero',0,'[email protected]...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
How to fix this?
A string literal such as 'Andrea'
is untyped and is not the same as a parameter of type varchar
. Test the following two lines in your psql console:
select 'Andrea';
select 'Andrea'::character varying;
The first will output Andrea
with default column name ?column?
the second will output Andrea
but with column name varchar
. From the documentation:
The notations varchar(n) and char(n) are aliases for character varying(n) and character(n), respectively.
To solve your problem, simply cast all the string literals in your function call to type varchar
(or character varying
). Also, the 0
should be cast to type money
, at the moment it is recognized as an integer
:
SELECT RegisterUser('Andrea'::varchar, 'Gianchero'::varchar, 0::money,...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With