0
def q1():
db.executescript(
    DROP VIEW IF EXISTS q1;

    CREATE VIEW q1 AS
    SELECT C.company_name, A.price_amount
    FROM companies as C, acquisitions as A
    WHERE C.status = 'acquired' and C.company_name = A.company_name;

    SELECT * FROM q1;
)
    return
q1()

When running the above, I'm getting the following error:

DROP VIEW IF EXISTS q1; ^ SyntaxError: invalid syntax

Can someone see what I'm doing wrong here?

ajfbiw.s
  • 401
  • 1
  • 8
  • 22

2 Answers2

0

You could use CREATE OR REPLACE VIEW instead, while removing the DROP VIEW line completely

radoh
  • 4,554
  • 5
  • 30
  • 45
  • Thanks, but do you see what is it that I'm doing wrong? – ajfbiw.s Feb 07 '16 at 00:27
  • What database are you using? If you are using mysql, it should work, according to docs. http://dev.mysql.com/doc/refman/5.7/en/drop-view.html – radoh Feb 07 '16 at 00:27
  • Hmm, according to https://www.sqlite.org/lang_dropview.html, it should be supported. But then here - http://stackoverflow.com/questions/3675032/drop-existing-table-in-sqlite-when-if-exists-operator-is-not-supported - they say that old version of sqlite doesn't support it, so that's the problem probably. – radoh Feb 07 '16 at 00:35
0

There could be 2 issues the way i see it. 1. you are not referring the schema name before dropping the view. 2. You are not committing the action performed by DDL command.

please refer to the sqlite site for syntax drop-view-stmt

Tarun Ande
  • 31
  • 7