我在 Postgres DB 中有下表:
CREATE TABLE resources_index (
hash varchar NOT NULL,
"name" varchar NOT NULL,
viewentry_id varchar NOT NULL,
value bytea NULL
);
我想使用以下准备好的语句sqlx
:
SELECT
t0.name,
t0.value
FROM
(
SELECT
name,
value
FROM
resources_index
WHERE
hash = $1
AND value :: BYTEA LIKE $2 :: BYTEA
) AS t0
LIMIT
$3
问题出现在以下行:
AND value :: BYTEA LIKE $2 :: BYTEA
Postgres DB 错误响应是:
ERROR: operator does not exist: character varying = bytea
查询执行如下:
let mut q = sqlx::query_as::<sqlx::Postgres, IndexRow>(&query);
for v in values.iter() {
log::debug!("bind value {}", v);
q = q.bind(v.as_bytes());
}
q.bind(limit).fetch_all(pool).await
对我来说,它看起来像是v
被铸造成的,VARCHAR
虽然它应该是BYTEA
。
你知道这是一个错误还是我做错了?