Skip to content

error: operator does not exist: text = integer #2724

Open
@jackhts4

Description

@jackhts4

Fail to update multiple rows in node-pg with prepared statement

CREATE TABLE user(
    id serial primary key,
    point INT
)

INSERT INTO user(point)
VALUES (11),(22),(33);

const { Pool, Client } = require('pg');
const pgPool = new Pool({...});
const query = `
    UPDATE user AS u 
    SET point = u2.point
    FROM(
        VALUES ($1, $2) ($3, $4)
    ) AS u2( id, point)
    WHERE u2.id = u.id;
`
const values = [1, 10, 2, 20]
pg.query(query, values)

(node:4676) UnhandledPromiseRejectionWarning: error: operator does not exist: text = integer

If changing $1 $2 $3 $4 to 1 20 2 20, the query worked correctly, but prepared statement failed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions