Skip to content

Instantly share code, notes, and snippets.

@gtallen1187
Last active August 29, 2015 13:55
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 gtallen1187/8357499bc95c919547a3 to your computer and use it in GitHub Desktop.
Save gtallen1187/8357499bc95c919547a3 to your computer and use it in GitHub Desktop.
create function charindex for postgres
CREATE OR REPLACE FUNCTION CHARINDEX(text, text, integer) RETURNS integer AS $$ SELECT CASE WHEN strpos(substr($2, $3+1), $1) = 0 THEN 0 ELSE strpos(substr($2, $3+1), $1) + $3 END; $$ LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment