-
Notifications
You must be signed in to change notification settings - Fork 60
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Hi, running this the following in the console is accepted:
INSERT INTO "counter_interfaces" ("device_id","device_type") VALUES ("123","3g") ON CONFLICT ("device_id", COALESCE("sim_id", "")) DO UPDATE SET "device_id" = EXCLUDED."device_id","device_type" = EXCLUDED."device_type","sim_id" = EXCLUDED."sim_id";
However, when run through exqlite I get an error:
iex(7)> {:ok, statement} = Exqlite.Sqlite3.prepare(conn, ~s<INSERT INTO "counter_interfaces" ("device_id","device_type") VALUES (?,?) ON CONFLICT ("device_id",coalesce("sim_id", "")) DO UPDATE SET "device_id" = EXCLUDED."device_id","device_type" = EXCLUDED."device_type","sim_id" = EXCLUDED."sim_id">) **
(MatchError) no match of right hand side value: {:error, "no such column: "}
The database definition is as follows:
create table("counter_interfaces") do
add :device_id, :string, null: false
add :device_type, :string, null: false
add :sim_id, :string, null: true
end
create unique_index("counter_interfaces", [:device_id, "coalesce(sim_id, '')"], name: :unique_counter_interfaces_on_any_sim_id)
What I'm trying to achieve is a situation where I have a unique constraint on multiple device_id/sim_id pairs, including the case that sim_id is nil (the default case for sqlite is that uniqueness is not enforced for columns which are null)
I'm not clear if this problem is coming from the sqlite parser or something in exqlite? That it works ok on the sqlite command line suggests exqlite? Any suggestions?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working