Skip to content

Instantly share code, notes, and snippets.

@Azerothian
Created May 31, 2016 01:04
Show Gist options
  • Save Azerothian/1752ce8d4123e4025b8270e11cede003 to your computer and use it in GitHub Desktop.
Save Azerothian/1752ce8d4123e4025b8270e11cede003 to your computer and use it in GitHub Desktop.
macaddr, inet ilike operators for postgresql
CREATE OR REPLACE FUNCTION ilikemac(macaddr, text)
RETURNS boolean AS
$$
BEGIN
RETURN ($1::text) ilike ($2) ;
END;
$$ LANGUAGE 'plpgsql' IMMUTABLE;
CREATE OPERATOR ~~* (
LEFTARG = macaddr,
RIGHTARG = text,
PROCEDURE = ilikemac
);
CREATE OR REPLACE FUNCTION ilikeinet(inet, text)
RETURNS boolean AS
$$
BEGIN
RETURN $1::text ilike $2;
END;
$$ LANGUAGE 'plpgsql' IMMUTABLE;
CREATE OPERATOR ~~* (
LEFTARG = inet,
RIGHTARG = text,
PROCEDURE = ilikeinet
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment