Skip to content

Instantly share code, notes, and snippets.

@mshakhomirov
Created November 24, 2022 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshakhomirov/9ca6e153da19c491034bd57995875308 to your computer and use it in GitHub Desktop.
Save mshakhomirov/9ca6e153da19c491034bd57995875308 to your computer and use it in GitHub Desktop.
-- One or more digits (\d+), optional period (\.?), zero or more digits (\d*).
with object as
(select '{"aed":3.6732,"afn":78.45934,"all":110.586428}' as rates)
, data as (
select "usd" as base_currency,
regexp_extract_all(rates, r'"[^"]+":\d+\.?\d*') as pair
from object
)
, splits as (
select base_currency, pair, split(pair, ':') positions
from data cross join unnest (pair) as pair
)
select base_currency, pair, positions[offset(0)] as rate_currency, positions[offset(1)] as rate
from splits
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment