-
-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax error on IfNotExists() when using sqlite dialect #704
Comments
Facing the same issue. Seems like SQLite does not support "IF NOT EXISTS" expression. I think the good solution would be to not add this expression to the final query and notify user about it. Example: // query_column_add.go AddColumnQuery.AppendQuery()
if q.ifNotExists {
if q.Dialect().Name() == dialect.SQLite {
log.Warn("Warning: SQLite dialect does not support IfNotExists() method, so it will be ignored")
} else {
b = append(b, "IF NOT EXISTS"...)
}
} |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed. |
I'd like to reopen this. Running into the same issue! |
I think the solution here should to be do some sort of check for sqlite:
The above behaviour is the intended behaviour when one is using |
Hi @j2gg0s, |
Yes, I will handle it next week. Maybe we could add new feature flag for this? |
That would work. Here's the workaround I have implemented if it helps:
And this is how the function is being used:
|
I’ve added an error handling logic first. It would be great if an adaptation solution could be provided for dialects that do not support ADD COLUMN IF NOT EXISTS, |
I had one minor request on the PR. Instead of returning
From a consumer perspective, it helps me do something meaningful if this happens. I can choose or not choose to do something on |
yeah @grandwizard28 , if db.Dialect().Name() != dialect.SQLite {
return q.IfNotExists()
} was the solution we went with in the end. And +1 to the ErrFeatureNotSupported error type |
I added an error type that includes the specific feature. |
Problem
When trying to add a new column if it doesn't exist, when using the sqlite shim, there exists a sytax error in the SQL. Works for PSQL. Just not SQLITE.
Example
Error
The text was updated successfully, but these errors were encountered: