

If the regex must match the whole string, you’ll need to use anchors. 'subject' ~ 'regexp' returns false, while 'subject' ~ '\\w' returns true. The tilde infix operator returns true or false depending on whether a regular expression can match part of a string, or not. AREs are far more powerful, and no more complicated if you don’t use functionality not offered by LIKE or SIMILAR TO. These use their own pattern languages, which are not discussed here. PostgreSQL also supports the traditional SQL LIKE operator, and the SQL:1999 SIMILAR TO operator.
#Postgresql where in code#
If you are migrating old database code to a new version of PostgreSQL, you can set PostgreSQL’s “ regex_flavor” run-time parameter to “ extended” instead of the default “ advanced” to make EREs the default. PostgreSQL versions prior to 7.4 supported POSIX Extended Regular Expressions only. Unfortunately, PostgreSQL’s regexp_replace function does not use the same syntax for the replacement text as Tcl’s regsub command, however. You should definitely review them if you’re not familiar with Tcl’s AREs. All my comments on Tcl’s regular expression flavor, like the unusual mode modifiers and word boundary tokens, fully apply to PostgreSQL.


This means that PostgreSQL supports the same three regular expressions flavors: Tcl Advanced Regular Expressions, POSIX Extended Regular Expressions and POSIX Basic Regular Expressions. PostgreSQL 7.4 and later use the exact same regular expression engine that was developed by Henry Spencer for Tcl 8.2. PostgreSQL Has Three Regular Expression Flavors
