Skip to content

Instantly share code, notes, and snippets.

@snelson82
Last active September 10, 2021 03:06
Show Gist options
  • Save snelson82/ae9d681031c8acdac4b81abbd7507fc3 to your computer and use it in GitHub Desktop.
Save snelson82/ae9d681031c8acdac4b81abbd7507fc3 to your computer and use it in GitHub Desktop.
-- Mixed with CASE, this will extract the float/digits in the last set of `()` in the string
CASE WHEN string_to_chop LIKE '%(%-%)%' THEN
NULL
ELSE
NULLIF (REPLACE(REPLACE(REGEXP_SUBSTR (string_to_chop, '\\([[:digit:]]+.[[:digit:]]+\\)$|\\([[:digit:]]+\\)$'), '(', ''), ')', ''), '')::float
END AS chopped_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment