Skip to content

Instantly share code, notes, and snippets.

@imfht
Created March 21, 2022 07:01
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 imfht/adb20db15f69b69d68f62c3e4d9f0f6c to your computer and use it in GitHub Desktop.
Save imfht/adb20db15f69b69d68f62c3e4d9f0f6c to your computer and use it in GitHub Desktop.
// from https://stackoverflow.com/a/45537886/8591480
CREATE FUNCTION is_valid_utf8(bytea) RETURNS boolean
LANGUAGE plpgsql AS
$$BEGIN
PERFORM convert_from($1, 'UTF8');
RETURN TRUE;
EXCEPTION
WHEN character_not_in_repertoire THEN
RAISE WARNING '%', SQLERRM;
RETURN FALSE;
END;$$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment