Closed mmarkmos closed 2 years ago
You are setting the OID of the Type
to 0
, which is not correct. If you need to specify the type explicitly in a statement (which you do not in this case), you will want to retrieve the type from the database by e.g. preparing a statement that returns it and pulling the type from the returned Statement
.
Thank you for your quick response, but when getting the type from
client.query("select unnest(enum_range(null::foo_type));");
or statticly setting the oid to 18157
im am still getting the same error.
This test passes for me.
#[test]
fn foo() {
#[derive(Debug, ToSql, FromSql, Eq, Hash, PartialEq, Copy, Clone)]
#[postgres(name = "foo_type")]
pub enum Foo {
#[postgres(name = "foo")]
FOO,
#[postgres(name = "bar")]
BAR,
}
let mut conn = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap();
conn.batch_execute(
"
CREATE TYPE pg_temp.foo_type AS ENUM ( 'foo', 'bar');
CREATE TEMPORARY TABLE foo_count(
id INTEGER ,
foo foo_type,
count BIGINT,
PRIMARY KEY (foo, id)
);
",
)
.unwrap();
let stmt = conn
.prepare("INSERT INTO foo_count (id, foo, count) VALUES ($1, $2, $3)")
.unwrap();
conn.execute(&stmt, &[&1i32, &Foo::FOO, &100i64]).unwrap();
}
Thank you again, for your swift help. Apparently I missed one enum in the sql, it was commented out 😅.
Interesting how the copy statement was still working.
I have the following SQL
and the following rust code
When trying to insert with BinaryCopyInWriter, it works.
But when trying to use a prepared Statement it doesn't work;
Getting the error