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?
Dois only valid in pgplsql. You can omit the do. Just concatenate the fragments (possibly each statement terminated by a semicolon. TheIF NOT EXISTSsyntax is invalid: use a WHERE clause instead.IF NOT EXISTSstatement runs fine when I execute the second file in postgres without concatenating. Should I run the complete script in pgplsql?