I'm in the process of learning postgres, I've already found a work around to this problem but I wanted to ask the community if something like this is even possible, maybe my syntax is just off.
DO $$ BEGIN
IF :MODIFYBY IS NOT NULL THEN
UPDATE User SET ModifyBy = :MODIFYBY WHERE UserId = :USERID;
UPDATE Profile SET ModifyBy = :MODIFYBY WHERE UserId = :USERID;
END IF;
END $$;
Receiving
syntax error at or near ":"
as :MODIFYBY is a parameter to this sql.
How can I test if a parameter is null?
Note: Running on PostgreSQL 9.6
Update:
It is possible my terminology is not correct. The full sql statement is this
BEGIN;
UPDATE User
SET Email = :EMAIL
,ModifyDate = now() at time zone 'utc'
WHERE
UserId = :USERID;
UPDATE Profile
SET FirstName = :FIRSTNAME
,LastName = :LASTNAME
,ModifyDate = now() at time zone 'utc'
WHERE
UserId = :USERID;
DO $$ BEGIN
IF :MODIFYBY IS NOT NULL THEN
UPDATE User SET ModifyBy = :MODIFYBY WHERE UserId = :USERID;
UPDATE Profile SET ModifyBy = :MODIFYBY WHERE UserId = :USERID;
END IF;
END $$;
COMMIT;
I added the DO $$ BEGIN and END $$; to get the IF statement to work...
:for parameter names.:in PL/pgSQL: postgresql.org/docs/current/static/plpgsql-declarations.html