I have the following statement in plpgsql
:
CREATE OR REPLACE FUNCTION json_update (mdata JSON) RETURNS void AS $$
DECLARE
mdata JSON = mdata;
mRecord record;
BEGIN
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SELECT
COALESCE(searches, 0) AS searched_quantity,
COALESCE(event, '2030-06-29') AS event_date,
INTO mRecord
FROM json_populate_record(NULL::my_app.app_report, mdata::JSON);
--here I also do some lengthy write operations and some calculation taking above data
COMMIT;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM json_update('{"event":"2021-07-07","searches":10}');
I get a syntax error in the line: BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
As far I know, this is how we set transaction levels outside of a stored procedure, and the syntax is fine if I do it in something like psql
command line. BTW, I execute this from the pgAdmin
's query panel.
Is there another syntax for setting transaction levels inside of stored procedures? BTW, I already read this and it doesn't really answer my question.