0

Several times now I've gotten the error "ERROR: syntax error at or near CREATE". I've played around with the formatting but can't seem to fix it. I'm hoping it's something minor someone can point out to me. Thanks in advance for the help!

-- View: mock_tool_cal

-- DROP VIEW mock_tool_cal;

CREATE OR REPLACE VIEW mock_tool_cal AS 
 SELECT toolcal."control#" AS old_control_number
   FROM staging.agg_staging_toolcal toolcal

ALTER TABLE mock_tool_cal
  OWNER TO postgres;
4
  • Did you try CREATE VIEW mock_tool_cal AS SELECT toolcal."control#" AS old_control_number FROM staging.agg_staging_toolcal toolcal Commented Jun 12, 2014 at 18:36
  • 1
    There is no error in your view create query (see this demo here sqlfiddle.com/#!15/0625b). It must be somewhere else. Show what you have before CREATE OR REPLACE VIEW. Commented Jun 12, 2014 at 18:40
  • @sany2k8 I just tried that out too, and no luck. I'm beginning to wonder if maybe it's a problem with the SQL admin program I'm using. Commented Jun 12, 2014 at 18:43
  • @Rahul I think that SQLFiddle confirms my suspicion. And I don't have anything in the ddl prior to "Create or Replace View" Commented Jun 12, 2014 at 18:45

2 Answers 2

2

You need a semicolon between the CREATE and ALTER commands

CREATE OR REPLACE VIEW mock_tool_cal AS 
SELECT toolcal."control#" AS old_control_number
FROM staging.agg_staging_toolcal toolcal

;

ALTER TABLE mock_tool_cal
OWNER TO postgres;
Sign up to request clarification or add additional context in comments.

Comments

0

Found the solution! As it turns out it was a problem with PGAdmin3. I was writing out the entire DDL, but hadn't realized it was already inserting "Create View mock_tool_cal". This meant I had two "Create View mock_tool_cal" lines hence the syntactical error.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.