I'm trying to insert data into the following table using the Npgsql ADO.NET provider:
CREATE SCHEMA core;
CREATE TABLE core.config(
name TEXT NOT NULL,
value TEXT NOT NULL,
CONSTRAINT pk_config PRIMARY KEY (name)
);
The first insert works fine but if I try to insert an item with the same name again, Npgsql just hangs. I would expect an exception to be thrown stating that the primary key constraint has been violated, but Npgsql just freezes instead. Sure enough, if I check the server logs I see this:
duplicate key value violates unique constraint "pk_config"
but this message doesn't seem to be getting back to Npgsql. Am I doing something wrong? My code is here:
using (NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=temp;User Id=postgres;Password=test1"))
{
conn.Open();
string cmdText = "INSERT INTO core.config(name, value) values ('item', 'value')";
using (NpgsqlCommand cmd = new NpgsqlCommand(cmdText, conn))
{
cmd.ExecuteNonQuery(); // This works fine
cmd.ExecuteNonQuery(); // Insert again: this hangs, but would expect an exception
}
}
This is a simplified version of a larger application (hence the use of a schema). I then tried creating the table in public (no schema specified). Interestingly this DOES generate an exception on the second call to ExecuteNonQuery():
Backend sent unrecognized response type
I'm a little lost as to whether this is a bug in Npgsql or whether it is something to do with Schema privileges (even though for this test I'm using the "postgres" superuser).
I'm using Npgsql 2.0.12.0