tekumara / fakesnow

Fake Snowflake Connector for Python. Run, mock and test Snowflake DB locally.
Apache License 2.0
108 stars 10 forks source link

fix: Support IF NOT EXISTS in CREATE DATABASE statements #108

Closed jsibbison-square closed 4 months ago

jsibbison-square commented 4 months ago

If a database already existed and we try to execute "CREATE DATABASE IF NOT EXISTS DB2" then it currently fails with error:

snowflake.connector.errors.ProgrammingError: 002043 (02000): Binder Error: Unique file handle conflict: Database "DB2" is already attached with path "...fakesnow-testl1jfag6s/DB2.db"

This commit adds support for this functionality by converting the statement to the duckdb syntax of ATTACH IF NOT EXISTS when the exists clause is present.

Up to you if you want to keep the test in test_fakes.py or only use the one in test_transforms.py

tekumara commented 4 months ago

Thank you!