Search code examples
databasepostgresqlstored-procedurescastingplpgsql

Error calling procedure in posgres "No procedure matches the given name and argument types. You might need to add explicit type casts."


CREATE or replace PROCEDURE mytransactions (n_transactions_id VARCHAR,
n_transaction_amount SMALLINT, 
n_transaction_date TIMESTAMP,
n_Delivery_date Date,
n_customer_id VARCHAR,
n_product_id VARCHAR,
n_store_id VARCHAR)
LANGUAGE plpgsql AS
  $BODY$
      BEGIN
        INSERT INTO transactions
(transactions_id, 
  transaction_amount,
  transaction_date,
Delivery_date,
customer_id,
product_id,
store_id)
        VALUES
  (n_transactions_id, n_transaction_amount, 
n_transaction_date,
n_Delivery_date,
n_customer_id,
n_product_id,
n_store_id);
      END;
  $BODY$

Here is my stored procedure, it creates successfully, however once I call it:

CALL mytransactions
('555', 3, current_timestamp , to_date('2022-10-25','YYYY-MM-DD'), 
  '003', '300', '002RW');

I get an error:

ERROR:  procedure mytransactions(unknown, integer, timestamp with time zone, date, unknown, unknown, unknown) does not exist
LINE 1: CALL mytransactions
             ^
HINT:  No procedure matches the given name and argument types. You might need to add explicit type casts.

Here you can find full tables https://dbfiddle.uk/9_NIQDw6


Solution

  • You need to typecast the parameters. This will work, allthough you'll get other errors when the procedure does it's things.

    CALL mytransactions
    ('555'::varchar, 3::smallint, current_timestamp::timestamp , to_date('2022-10-25','YYYY-MM-DD'), 
      '003'::varchar, '300'::varchar, '002RW'::varchar);