Kabi
Kabi

Reputation: 2045

Insert into a table with Pl/pgsql

I try to add an UUID value into a table with pl/pgsql. this is my code:

CREATE OR REPLACE FUNCTION "Surrogate_gen"()
  RETURNS uuid AS
$BODY$DECLARE 
uid UUID;
BEGIN
uid:=(select uuid_generate_v1());
INSERT INTO public.Surrogate_Table(wert) VALUES(uid);
RAISE NOTICE 'My UUID is %',uid;
return uid;
END
$BODY$

If I run this code an error occured an says: Relation »public.surrogate_table« doesnt exist

but this table exists in my DB. How can I solve this problem? Thank you

Upvotes: 0

Views: 1258

Answers (1)

mu is too short
mu is too short

Reputation: 434615

I'd guess that you created the surrogate table with something like this:

create table "Surrogate_Table" (...)

Note the quotes around the table name and also note that the error message is talking about surrogate_table. PostgreSQL folds all unquoted identifiers to lower case but you have a mixed-case table name. Add some more double quotes to get the right case:

INSERT INTO public."Surrogate_Table"(wert) VALUES(uid);

Upvotes: 2

Related Questions