Home > other >  return a value from insert stored procedure (not function)?
return a value from insert stored procedure (not function)?

Time:01-18

I'm new for postgresql and getting ERROR while calling stored procedure in postgresql:

ERROR: column reference "id" is ambiguous. LINE 5: (id,isactive,createddatetime, fullname) RETURNING id

create or REPLACE procedure increase(
    inout id character varying(50),
    in isactive boolean,
    in createddatetime DATE,
    in fullname text
)
LANGUAGE 'plpgsql'
AS $$
begin
INSERT INTO 
public.contactus 
(id,isactive,createddatetime, fullname) 
VALUES   
(id,isactive,createddatetime, fullname) RETURNING id into id;
end ;
$$;

CALL increase('Test001',true,'1997-10-01','ok msg')

Please provide the example in same format. So, it will good for understating me and others.

CodePudding user response:

The function parameters have the same name as the table columns. That constitutes an ambiguity. Avoid that by either choosing different parameter names or by qualifying the parameters with the function name in the SQL statement: increase.id.

CodePudding user response:

I'm adding this example that help to other.

create or REPLACE procedure increase(
    inout id character varying(50),
    in isactive boolean,
    in createddatetime DATE,
    in fullname text
)
LANGUAGE 'plpgsql'
AS $$
begin
INSERT INTO 
public.contactus 
(id,isactive,createddatetime, fullname) 
VALUES   
(id,isactive,createddatetime, fullname) RETURNING increase.id into id;
end ;
$$;

CALL increase('Test001',true,'1997-10-01','1997-10-21','ok msg')
  •  Tags:  
  • Related