Created
November 24, 2022 15:27
-
-
Save mshakhomirov/9ca6e153da19c491034bd57995875308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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