porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sql array error when upgrade to version 3.4.4

janiu-001 opened this issue · comments

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}'

Dear expert,

any update on this issue?

sql.array is deprecated since v2 - just put the array there directly