Skip to content

Document that json/jsonb is returned as string in postgresql #4179

@CaselIT

Description

@CaselIT

What feature or improvement would you like to see?

I think it would make sense to document that the json/jsonb dtypes are returned as strings here https://arrow.apache.org/adbc/current/driver/postgresql.html, or at least update the Unknown Types section to mention that it's not always a binary that's returned

from adbc_driver_postgresql import dbapi

q = """SELECT
'{"foo": 1, "bar": "baz"}'::jsonb a,
'{"foo": 1, "bar": "baz"}'::json b
"""

def go():
    with dbapi.connect("postgresql://scott:tiger@localhost:5432/scott") as conn:
        with conn.cursor() as cur:
            cur.execute(q)
            row = cur.fetchone()
            print(row, [type(col) for col in row])
            t = cur.execute(q).fetch_arrow_table()
            print(t)

go()

this prints

('{"bar": "baz", "foo": 1}', '{"foo": 1, "bar": "baz"}') [<class 'str'>, <class 'str'>]
pyarrow.Table
a: string
b: string
----
a: [["{"bar": "baz", "foo": 1}"]]
b: [["{"foo": 1, "bar": "baz"}"]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions