Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bigquery)!: Add support for STRING function #4284

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

VaggelisD
Copy link
Collaborator

This PR adds support for BQ's STRING(...) function, which turns input expressions into STRINGs. There are two supported versions:

  1. JSON based: STRING(json_expr)
  2. TIMESTAMP based: STRING(timestamp_expression[, time_zone])

Both variants are transpiled to CAST(... AS VARCHAR) for all other dialects; For the (2) variant with time_zone supplied, the timestamp is passed through exp.ConvertTimezone for the timezone conversion:

bigquery> SELECT STRING("2008-12-25 15:30:00", "America/New_York") AS string;
2008-12-25 10:30:00-05

snowflake> SELECT CAST(CONVERT_TIMEZONE('UTC', 'America/New_York', '2008-12-25 15:30:00') AS VARCHAR);
2008-12-25 10:30:00.000

duckdb> SELECT CAST(CAST('2008-12-25 15:30:00' AS TIMESTAMP) AT TIME ZONE 'UTC' AT TIME ZONE 'America/New_York' AS TEXT) AS color;
┌─────────────────────┐
│        color        │
│       varchar       │
├─────────────────────┤
│ 2008-12-25 10:30:00 │
└─────────────────────┘

Docs

BQ JSON STRING() | BQ TIMESTAMP STRING()

sqlglot/expressions.py Show resolved Hide resolved
sqlglot/generator.py Outdated Show resolved Hide resolved
@georgesittas georgesittas merged commit c3c1997 into main Oct 24, 2024
6 checks passed
@georgesittas georgesittas deleted the vaggelisd/bq_string branch October 24, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants