Issue
The syntax below is valid in PostgreSQL, but ';' characters cause improper separation and execution.
CREATE OR REPLACE RULE insert_docents AS ON INSERT TO docents DO INSTEAD (
INSERT INTO users
VALUES (default,
new.email,
new.name,
new.hash_salt,
new.roles)
ON CONFLICT (id) DO NOTHING;
INSERT
INTO docent_users
VALUES (currval('users_id_seq'),
new.introduce_short,
new.introduce_long,
new.video,
new.images)
);
Caused by: org.springframework.r2dbc.connection.init.ScriptStatementFailedException: Failed to execute SQL script statement #4 of class path resource [db/schema.sql]: CREATE OR REPLACE RULE insert_docents AS ON INSERT TO docents DO INSTEAD ( INSERT INTO users VALUES (default, new.email, new.name, new.hash_salt, new.roles) ON CONFLICT (id) DO NOTHING; nested exception is io.r2dbc.postgresql.ExceptionFactory$PostgresqlBadGrammarException: [42601] syntax error at end of input
another example
CREATE OR REPLACE FUNCTION update_emp_view() RETURNS TRIGGER AS $$
BEGIN
--
-- Perform the required operation on emp, and create a row in emp_audit
-- to reflect the change made to emp.
--
IF (TG_OP = 'DELETE') THEN
DELETE FROM emp WHERE empname = OLD.empname;
IF NOT FOUND THEN RETURN NULL; END IF;
OLD.last_updated = now();
INSERT INTO emp_audit VALUES('D', user, OLD.*);
RETURN OLD;
ELSIF (TG_OP = 'UPDATE') THEN
UPDATE emp SET salary = NEW.salary WHERE empname = OLD.empname;
IF NOT FOUND THEN RETURN NULL; END IF;
NEW.last_updated = now();
INSERT INTO emp_audit VALUES('U', user, NEW.*);
RETURN NEW;
ELSIF (TG_OP = 'INSERT') THEN
INSERT INTO emp VALUES(NEW.empname, NEW.salary);
NEW.last_updated = now();
INSERT INTO emp_audit VALUES('I', user, NEW.*);
RETURN NEW;
END IF;
END;
$$ LANGUAGE plpgsql;
Expect
Not use ;
character between $$
... $$
or (
... )
as statement separator
Comment From: snicoll
Superseded by #28091