I'm new to PostgreSQL and before I worked on SQL Server. I want to create a table with a key and a JSON column to write and update my JSON field. I use the jsonb_set
method in PostgreSQL.
For example
update "Comment"
set "testJsonb" = jsonb_set("testJsonb",'{uuid}',SomeMethod,true)
I want to replace this function uuid_generate_v4()
with SomeMethod. I figured that I should not put function there, then I decided to put a variable there, but I can't do that and I don't know why.
DECLARE cnt varchar;
as you see above code doesn't work
DO $$
DECLARE
myVar VARCHAR := 'myValue';
BEGIN
select myVar
END $$;
CREATE OR REPLACE FUNCTION clean_emp()
RETURNS void AS $$
DECLARE cnt varchar;
BEGIN
END;
$$ LANGUAGE plpgsql;
I can declare a variable in a function, but I don't want this because I can't put a function in SomeMethod
in jsonb_set
. Am I wrong? Or should this be done in another way?