Skip to content

jsonb query error with jsonb_array_elements WITH ORDINALITY  #3078

Open
@piyongcai

Description

@piyongcai

Version

1.24.0

What happened?

A bug happened!

Relevant log output

column "elem" does not exist

Database schema

CREATE TABLE IF NOT EXISTS wallet_tmp (
    mobile  VARCHAR PRIMARY KEY,        -- 手机号码
    tickets JSONB NOT NULL default '[]' -- 我的票夹
);

SQL queries

-- name: RemoveTicketFromWalletTmp :exec
WITH elements AS (
    SELECT (index-1)::INT AS idx
      FROM wallet_tmp,
           jsonb_array_elements(tickets) WITH ORDINALITY arr(elem, index)
      WHERE mobile = $1
        AND elem->>'ticket_no' = $2
)
UPDATE wallet_tmp
   SET tickets = tickets - elements.idx
  FROM elements
 WHERE wallet_tmp.mobile = $1;

Configuration

No response

Playground URL

No response

What operating system are you using?

No response

What database engines are you using?

No response

What type of code are you generating?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNew issues that hasn't been reviewed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions