6

I get the error "42883: operator does not exist: integer =@ integer" Npgsql.PostgresException when trying to pass parameters to a DO block:

var cmd = new NpgsqlCommand();
cmd.CommandText = 
@"DO $$ 
BEGIN
IF EXISTS (SELECT id FROM pub.table1 WHERE id = @id) THEN
    UPDATE pub.table1 
    SET Field1 = @Field1
       ,Field2 = @Field2
    WHERE id = @id;
ELSE
    INSERT INTO pub.table1 (id, Field1, Field2) 
    VALUES (@id, @Field1, @Field2);
END IF;

END $$;";

cmd.Parameters.AddWithValue("@id", 1);
cmd.Parameters.AddWithValue("@Field1", "text");
cmd.Parameters.AddWithValue("@Field2", "text2");

Otherwise connection to postgres works and also (classic) queries work when passing parameters; e.g.:

cmd.CommandText = @"SELECT * FROM pub.table1 WHERE id = @id;";

Is it not possible to pass parameters to a "DO" block or am I missing something?

Thank you. M

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.