sqlite3 views, if not exists clause

Josh noone at nowhere.com
Tue Nov 14 08:32:43 EST 2006


Hi,
I'm running into a problem when trying to create a view in my sqlite 
database in python. I think its a bug in the sqlite3 api that comes with 
python 2.5.

This works as expected:
  conn = sqlite3.connect(':memory:')
  conn.execute("create table foo (a int,b int)")
  conn.execute('create view bar as select * from foo')

This fails as expected:
  conn = sqlite3.connect(':memory:')
  conn.execute("create table foo (a int,b int)")
  conn.execute('create view bar as select * from foo')
  conn.execute('create view bar as select * from foo')
with exception "sqlite3.OperationalError: table bar already exists".
Weird that it fails with TABLE bar already exists, but this is the message 
that sqlite actually returns so it is not python's fault.

THIS DOES NOT WORK, but it should!
  conn = sqlite3.connect(':memory:')
  conn.execute("create table foo (a int,b int)")
  conn.execute('create view if not exists bar as select * from foo')
it fails with exception "sqlite3.OperationalError: near "not": syntax error"

Can anyone confirm, or pass this on to the appropriate person?
Thanks!
Josh






More information about the Python-list mailing list