Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql array error when upgrade to version 3.4.4 #853

Closed
janiu-001 opened this issue Apr 26, 2024 · 2 comments
Closed

sql array error when upgrade to version 3.4.4 #853

janiu-001 opened this issue Apr 26, 2024 · 2 comments

Comments

@janiu-001
Copy link

janiu-001 commented Apr 26, 2024

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}'
@janiu-001
Copy link
Author

Dear expert,

any update on this issue?

@porsager
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants