Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgsmus/3c7ed5e443f28c0f83e8684b508c359e to your computer and use it in GitHub Desktop.
Save mgsmus/3c7ed5e443f28c0f83e8684b508c359e to your computer and use it in GitHub Desktop.
PostgreSQL create UUID max aggregate function
CREATE OR REPLACE FUNCTION max (uuid, uuid)
RETURNS uuid AS $$
BEGIN
IF $1 IS NULL OR $1 < $2 THEN
RETURN $2;
END IF;
RETURN $1;
END;
$$ LANGUAGE plpgsql;
CREATE AGGREGATE max (uuid)
(
sfunc = max,
stype = uuid
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment