Skip to content

Instantly share code, notes, and snippets.

@devodo
Created March 16, 2016 11:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save devodo/8b39748d65e8185fbd89 to your computer and use it in GitHub Desktop.
Save devodo/8b39748d65e8185fbd89 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
);
@pematt
Copy link

pematt commented Apr 30, 2022

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment