I have two files that both work fine when executing them in Postgres.
File 1
CREATE TABLE ContractStatusEnum (
id SERIAL PRIMARY KEY,
description VARCHAR(4000) NOT NULL
);
*File 2
DO $$ BEGIN
IF NOT EXISTS (SELECT * FROM ContractStatusEnum WHERE id = 1) THEN
INSERT INTO ContractStatusEnum (id, description) VALUES
(1, 'Ordered'),
(2, 'Active'),
(3, 'Stopped'),
(4, 'Canceled'),
(10, 'Inactive');
END IF;
END $$
However, if I just put them together in one file, it fails with
ERROR: syntax error at or near “DO”
LINE 6: DO $$ BEGIN
On MS SQL I can solve this by creating a new context by putting a GO statement between two scripts. Any clue how to do it in Postgres 9?
You need to terminate your
DOblock with a semicolon.The following works for me:
I saved the statements in f1.sql (create table) and f2.sql (do block):