Search code examples
sqlpostgresqlpostgresql-11postgresql-12

Procedure does not exist PostgreSQL


I've created procedure to insert new record

CREATE OR REPLACE PROCEDURE PUBLIC."saveStudent"(
    "fName_val" character varying,
    "sName_val" character varying,
    patr_val character varying,
    "DoB_val" DATE,
    GROUP_ID INTEGER,
    instructor_id INTEGER)
LANGUAGE 'plpgsql'

AS $BODY$ BEGIN
 INSERT INTO PUBLIC.student(
    "fName", "sName", "patronymic", "DoB", "group", instructor)
    VALUES (fName_val, sName_val, patr_val, DoB_val, GROUP_ID,instructor_id);
END; $BODY$

But when i try to call it I get error

CALL public.saveStudent(
    'It', 
    'is', 
    'Test', 
    '23/09/1999', 
    0, 
    1
)

procedure savestudent(unknown, unknown, unknown, unknown, integer, integer) does not exist

What cause it?


Solution

  • Try calling the procedure like this:

    CALL "saveStudent" (
        'It'::character varying, 
        'is'::character varying, 
        'Test'::character varying, 
        '2019-09-23'::date, 
        0, 
        1
    );
    

    You are just making your life harder by using double quotes for all the identifiers. This means that you need to use double quotes when referring to them, because the double quotes enforce the specific case of the string. That is cumbersome and prone to errors (and you see here). Plus, it will wear out your double quote key if you write lots of code.

    Here is a db<>fiddle. Note this still generates an error, but an error from the procedure being executed.