Skip to content

Instantly share code, notes, and snippets.

@renatocron
Created July 26, 2018 11:34
Show Gist options
  • Save renatocron/f1718568904ed70bc32aefe6258cd266 to your computer and use it in GitHub Desktop.
Save renatocron/f1718568904ed70bc32aefe6258cd266 to your computer and use it in GitHub Desktop.
with orig as (
select 'original value'::text as foo limit 1
),
orig_if_not as (
select 'the value if first query returns no rows'::text as foo
)
select coalesce(a.foo, b.foo) as the_foo
from orig a
right join orig_if_not b on (a.foo is not null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment