Using SQLite 3.37.2. The following queries work:
DROP TABLE IF EXISTS MyTable;
CREATE TABLE IF NOT EXISTS...;
But a similar query on a column generates an error:
ALTER TABLE MyTable DROP COLUMN IF EXISTS MyField;
Remove IF EXISTS and the query works fine.
Does SQLite support IF EXISTS and IF NOT EXISTS for adding/dropping columns? This related question appears to answer "no", though that was back in 2010. Perhaps something has changed in the latest version(s).
This recent SQLite forum question on the same subject is answered by the primary SQLite developer, Richard Hipp. Based on the Richard's answer, and the observation from @AnonCoward, the following is true:
As of v3.37.2 (January 2022), SQLite does NOT support either of the following:
ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...;
ALTER TABLE ... DROP COLUMN IF EXISTS ...;
There is currently a prototype implementation of this functionality in SQLite. The git check-in can be viewed here. Not slated for release in the upcoming v3.38.0 release, but sometime in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With