Created
December 17, 2018 20:32
-
-
Save mwotton/3595256425790339822ecdb8084c5c1d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
create function polycast(input text, typ anyelement) returns anyelement language plpgsql immutable as | |
$$ | |
begin | |
return input::anyelement; | |
end; | |
$$; | |
create function nullable(input text, typ anyelement) returns anyelement language plpgsql immutable as | |
$$ | |
begin | |
return polycast(input, typ); | |
exception | |
when others then | |
return typ; | |
end;$$; | |
postgres=# select 1 where nullable('abc', null::timestamptz) < nullable('2018-01-01 00:00:00', null::timestamptz); | |
?column? | |
---------- | |
(0 rows) | |
postgres=# select 1 where nullable('2018-01-01 00:00:00', null::timestamptz) < nullable('2018-01-01 10:00:00', null::timestamptz); | |
?column? | |
---------- | |
1 | |
(1 row) | |
postgres=# select 1 where nullable('2018', null::numeric) < nullable('2019', null::numeric); | |
?column? | |
---------- | |
1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment