Skip to content

No function matches the given name and argument types 'json_extract(JSON, BOOLEAN)' #10786

Closed

Description

@tekumara

What happens?

When using json_extract on a json field with only 0 or 1 values:

Error: Binder Error: No function matches the given name and argument types 'json_extract(JSON, BOOLEAN)'. You might need to add explicit type casts.
        Candidate functions:
        json_extract(VARCHAR, BIGINT) -> JSON
        json_extract(VARCHAR, VARCHAR) -> JSON
        json_extract(VARCHAR, VARCHAR[]) -> JSON[]
        json_extract(JSON, BIGINT) -> JSON
        json_extract(JSON, VARCHAR) -> JSON
        json_extract(JSON, VARCHAR[]) -> JSON[]

To Reproduce

CREATE TEMPORARY TABLE TBL (COL JSON);
INSERT INTO TBL (COL) SELECT (TO_JSON({'K1': {'K2': 1}}));
SELECT COL FROM TBL WHERE COL -> '$.K1' -> '$.K2' > 0;

OS:

macOS

DuckDB Version:

0.10.1.dev240

DuckDB Client:

python

Full Name:

Oliver Mannion

Affiliation:

Xero

Have you tried this on the latest nightly build?

I have tested with a nightly build

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • Yes, I have

Activity

  1. Mause commented on Feb 21, 2024

    @Mause
    Contributor

    Looks like this is a case of > having a higher precedence than ->?

    This seems to work fine:

    SELECT COL FROM TBL WHERE (COL -> '$.K1' -> '$.K2') > 0;
  2. chanon commented on Feb 22, 2024

    @chanon

    Same issue seems to happen with = and other operators

    eg.

    SELECT COL FROM TBL WHERE COL->'$.K1'->'$.K2' = 0;
    

    and

    SELECT COL FROM TBL WHERE COL->'$.K1'->'$.K2' is not null;
    

    result in the same error

  3. hannes commented on Feb 26, 2024

    @hannes
    Member

    There is a precedence conflict here, for lambdas we want = to have higher precedence than ->:

    select list_transform([1,0,2], x -> x=0);

    But for JSON we want -> to have higher precedence than =:

    select (json '{"field": 42}')->'field' = 42;

    As such there is no good solution here - so parenthesis are just going to be required here. We'll add a note to the documentation.

  4. added
    Needs DocumentationUse for issues or PRs that require changes in the documentation
    on Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs DocumentationUse for issues or PRs that require changes in the documentationreproduced

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions