I found multiple solutions of running a query only if a parameter is not null, but none of them seems to fit my scenario.
I have to following UPDATE script:
DO '
BEGIN
IF EXISTS
(SELECT 1 FROM pg_class where relname=$J$scm_repos$J$)
THEN
UPDATE scm_repos repos SET token_id=(SELECT token_id FROM scm_orgs orgs WHERE repos.org_id=orgs.id);
UPDATE scm_orgs SET token_id = NULL;
END IF ;
END;
'
I want the the 1st UPDATE script to run only if the token_id on the scm_orgs is not null.
What is the proper way doing it?