Skip to content

incorrect parentheses with casting #168

@mmkal

Description

@mmkal

hi, it seems like some stuff is going wrong with cast-ed jsonb dereferencing:

import * as pgsqlAstParser from 'pgsql-ast-parser'

const input = `select json->'foo'::text->>'bar'::text as bar from json_table`
const ast = pgsqlAstParser.parse(input)[0]
const output = pgsqlAstParser.toSql.statement(ast)

console.log(output) // SELECT ((((json->'foo')::text )->>'bar')::text ) AS bar  FROM **table_with_json

So you can see it casts json->'foo' to text, and then when we try to do ->>'bar', there will be an error because ->> is an operator on jsonb, not text.

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