when running the following sql command I get an error
CREATE OR REPLACE FUNCTION create_constraint_if_not_exists (t_name text, c_name text, constraint_sql text)
RETURNS void
AS
$BODY$
begin
-- Look for our constraint
if not exists (select constraint_name
from information_schema.constraint_column_usage
where table_name = t_name and constraint_name = c_name) then
execute 'ALTER TABLE ' || t_name || ' ADD CONSTRAINT ' || c_name || ' ' || constraint_sql;
end if;
end;
$BODY$
LANGUAGE plpgsql VOLATILE;
the error is
sql-migrate up 1
Migration failed: pq: unterminated dollar-quoted string at or near "$BODY$
begin
-- Look for our constraint
if not exists (select constraint_name
from information_schema.constraint_column_usage
where table_name = t_name and constraint_name = c_name) then
execute 'ALTER TABLE ' || t_name || ' ADD CONSTRAINT ' || c_name || ' ' || constraint_sql;
end if;
end;
" handling 20180126120940-PREFEDINED_FUNCTIONS.sql
This is a parsing error when there are too many semicologns in the function body. Chaning the sql command to the following fixes the error.
CREATE OR REPLACE FUNCTION create_constraint_if_not_exists (t_name text, c_name text, constraint_sql text)
RETURNS void
AS
$BODY$
begin
-- Look for our constraint
if not exists (select constraint_name
from information_schema.constraint_column_usage
where table_name = t_name and constraint_name = c_name) then
execute 'ALTER TABLE ' || t_name || ' ADD CONSTRAINT ' || c_name || ' ' || constraint_sql;end if;end;$BODY$LANGUAGE plpgsql VOLATILE;
when running the following sql command I get an error
the error is
This is a parsing error when there are too many semicologns in the function body. Chaning the sql command to the following fixes the error.