sql array error when upgrade to version 3.4.4
janiu-001 opened this issue · comments
Jason Niu commented
Dear expert:
Would you help on the issue described as follows? After upgrading postures to 3.4.4, I got a type error when saving array.
Procedure:
the sql for creating table:
CREATE TABLE IF NOT EXISTS public.array_testing
(
test_id character varying COLLATE pg_catalog."default" NOT NULL DEFAULT uuid_generate_v4(),
topics character varying[] COLLATE pg_catalog."default",
CONSTRAINT "PK_2af71aed4110cd4e9d7a8b7d5f1" PRIMARY KEY (test_id)
)
Code:
test('array testing', async () => {
const test_id = 'test_id';
const topics = ['Default'];
await sql`
INSERT INTO array_testing (test_id, topics)
VALUES (
${test_id},
${sql.array(topics)}
)
`;
});
Errors logs in postgres database by enabling log_statement:
2024-04-26 06:51:33.347 UTC [138] ERROR: column "topics" is of type character varying[] but expression is of type text at character 79
2024-04-26 06:51:33.347 UTC [138] HINT: You will need to rewrite or cast the expression.
2024-04-26 06:51:33.347 UTC [138] STATEMENT:
INSERT INTO array_testing (test_id, topics)
VALUES (
$1,
$2
)
But it is ok with the postgres version 3.4.3, the difference is the parameter
is passed correctly
2024-04-26 06:50:15.253 UTC [135] STATEMENT:
INSERT INTO array_testing (test_id, topics)
VALUES (
$1,
$2
)
2024-04-26 06:50:15.256 UTC [135] LOG: execute ktvouhx7g7p3:
INSERT INTO array_testing (test_id, topics)
VALUES (
$1,
$2
)
2024-04-26 06:50:15.256 UTC [135] DETAIL: parameters: $1 = 'test_id', $2 = '{Default}'
Jason Niu commented
Dear expert,
any update on this issue?
Rasmus Porsager commented
sql.array is deprecated since v2 - just put the array there directly