Created
February 15, 2019 21:48
-
-
Save petermoresi/437109548d6afa4bdb2f04be89668319 to your computer and use it in GitHub Desktop.
postgres max user defined function
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
create EXTENSION plv8; | |
create EXTENSION pltcl; | |
CREATE FUNCTION sql_max(integer, integer) RETURNS integer AS $$ | |
BEGIN | |
IF $1 > $2 THEN | |
RETURN $1; | |
END IF; | |
RETURN $2; | |
END; | |
$$ LANGUAGE plpgsql STRICT; | |
CREATE FUNCTION tcl_max(integer, integer) RETURNS integer AS $$ | |
if {$1 > $2} {return $1} | |
return $2 | |
$$ LANGUAGE pltcl STRICT; | |
CREATE FUNCTION v8_max(integer, integer) RETURNS integer AS $$ | |
if ($1 > $2) { return $1 } | |
return $2 | |
$$ LANGUAGE plv8 STRICT; | |
select tcl_max(2,3), v8_max(2,3), sql_max(2,3); | |
drop function sql_max(integer, integer); | |
drop function v8_max(integer, integer); | |
drop function tcl_max(integer, integer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment