I'm in the process of migrating a lot of SQL (in LookML) from PostgreSQL to BigQuery (Standard SQL). Documenting the quirks I find along the way here!
x::int
cast(x as int64)
substring('asdf' from '^(.*)')
regexp_extract('asdf', '^(.*)')
BigQuery's concat()
args must be cast to string
s first. Double-pipes are no bueno in BQ.
concat('#', id)
'#' || id
Note - concatenating a string with a null
string will return the entire concatenated string as null
. This is different than in PostgreSQL, which will simply treat the null
string as a blank string.
concat('#', coalesce(cast(id as string), ''))
Standard SQL date function reference
The following examples create a naive timestamp of whatever time it is in NYC.
(current_timestamp::timestamptz at time zone 'America/New_York')::timestamp
datetime(current_timestamp, 'America/New_York')
d1 + '9 days'::interval
d1 - '9 days'::interval
date_add(d, interval 9 day)
date_sub(d, interval 9 day)
d2 - d1
date_diff(d1, d2, day)
SQL table names need backticks and schema name updates.
sql_table_name: pg_schema.pg_table_name ;;
sql_table_name: `bq_schema.bq_table_name` ;;