I'm trying to build a function that returns some text. The text includes a BEGIN
statement which seems to cause an error:
CREATE OR REPLACE FUNCTION create_trigger() RETURNS TEXT AS $$
BEGIN
RETURN
'CREATE OR REPLACE FUNCTION update_view() RETURNS trigger AS $$
BEGIN -- error is near this begin
IF TG_OP = ''INSERT'' THEN DO SOMETHING;
ELSIF TG_OP = ''UPDATE'' THEN DO SOMETHING;
END IF;
RETURN NEW;
END;
$$ language plpgsql';
END;
$$ language plpgsql
I get a syntax error near the word BEGIN
in the return statement and don't understand why, as I'm only trying to return some text. Is this because plpgsql
recognizes the word BEGIN
even if it is in a string portion of the code?