Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/sqlalchemy-bigquery/sqlalchemy_bigquery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ def visit_BINARY(self, type_, **kw):

visit_VARBINARY = visit_BLOB = visit_BINARY

def visit_JSON(self, type_, **kw):
return "JSON"
Comment on lines +625 to +626
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding an alias for JSONB to improve compatibility with models that use the JSONB type (e.g., those originally designed for PostgreSQL). Since BigQuery's JSON type is binary-optimized, it is the appropriate mapping for JSONB in this dialect.

    def visit_JSON(self, type_, **kw):
        return "JSON"

    visit_JSONB = visit_JSON


def visit_NUMERIC(self, type_, **kw):
if (type_.precision is not None) and isinstance(
kw.get("type_expression"), Column
Expand Down
12 changes: 12 additions & 0 deletions packages/sqlalchemy-bigquery/tests/unit/test_table_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ def test_table_default_rounding_mode_dialect_option(faux_conn):
)


def test_table_with_json_columns(faux_conn):
setup_table(
faux_conn,
"some_table",
sqlalchemy.Column("some_stuff", sqlalchemy.JSON),
)

assert " ".join(faux_conn.test_data["execute"][-1][0].strip().split()) == (
"CREATE TABLE `some_table` ( `some_stuff` JSON )"
)


def test_table_clustering_fields_dialect_option_no_such_column(faux_conn):
with pytest.raises(sqlalchemy.exc.NoSuchColumnError):
setup_table(
Expand Down
Loading