Skip to content

sql: SELECT DISTINCT jsoncol->foo is broken #24436

@benesch

Description

@benesch

Realistic reproduction:

> create table t (ext json);
> insert into t values ('{"foo": "bar"}');
> select distinct ext->'foo' from t;
pq: unable to encode table key: *tree.DJSON

Minimal reproduction:

> select distinct '{}'::json;
pq: unable to encode table key: *tree.DJSON

@justinj suggests that this is because we can't currently key-encode JSON values. As a workaround:

> select distinct ext->>'foo' from t;
+-------------+
| ext->>'foo' |
+-------------+
| bar         |
+-------------+
(2 rows)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sql-encodingRelating to the SQL/KV encoding.A-sql-executionRelating to SQL execution.A-sql-jsonJSON handling in SQL.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.S-3-ux-surpriseIssue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption.docs-donedocs-known-limitation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions