I am trying to raise an issue in a Postgresql function using a concatenated message, but I get an error message at runtime:
error: syntax error at or near "msg"
The code is the following:
CREATE OR REPLACE FUNCTION insertUserAccount(
id bigint,
nname varchar(40),
email varchar(40),
pwd varchar,
status smallint,
last_update bigint,
preferences json,
bits integer,
adm json)
RETURNS bigint AS $$
DECLARE
rowc INTEGER;
ret_id bigint;
msg text;
BEGIN
...
IF ( rowc > 0 ) THEN
msg = 'User account already exists or name or email is unavailable (id=' || id
|| ', name=' || nname
|| ', email=' || email || ')';
RAISE EXCEPTION msg USING ERRCODE = '23505';
ELSE
...