Skip to content

Instantly share code, notes, and snippets.

@jeff

jeff/nix0n.sql Secret

Created August 12, 2015 00:17
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 jeff/4b6252dd190d175b9e03 to your computer and use it in GitHub Desktop.
Save jeff/4b6252dd190d175b9e03 to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION plv8_regexp_test(regexp text[2], subject text) RETURNS BOOLEAN AS $$
return (new RegExp(regexp[0], regexp[1])).test(subject);
$$ LANGUAGE plv8;
CREATE OR REPLACE FUNCTION plv8_regexp_test(regexp text, subject text) RETURNS BOOLEAN AS $$
BEGIN
RETURN plv8_regexp_test(ARRAY[regexp], subject);
END;
$$ LANGUAGE plpgsql;
SELECT id, date_added, name
FROM testable
WHERE plv8_regexp_test('^d', name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment