Skip to content

Help with ::int inside a ::jsonb casted query #2169

@RNCTX

Description

@RNCTX

Hey folks, I'm using IBM's Node RED tool to mock up a few concepts and in multiple Postgres packages for that platform that use pg, am able to reproduce a jsonb update query issue that leads me to think I have a syntax problem I can't find a solution to. I'm using Node v. 12.13.0

I have a table "product" with a jsonb column "data", without indexes other than "pk" the serialized primary key. The data column has a property "quantity" that I initially insert with value "1" and am trying to conditionally increment based on a check of its existence in the flow of the application.

The query...

UPDATE product SET data = data || ('{"quantity": ' || ((data->>'quantity')::int + 1) || '}')::jsonb WHERE pk = 1;

...works fine in the pgsql shell, but sent over via pg it fails with:

image

This plugin requires pg 7.11.0, this one requires 7.18.2, and both return the same error when trying to execute the above query with the table and pk pulled in from prior function variables.

I tried using the recommendation here to change the query to...

UPDATE product SET data = jsonb_set(data || ('{"quantity": ' || jsonb_build_object((data->'quantity')::int + 1) || '}')::jsonb) WHERE pk = 1;

But I get the same error.

Any help appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions