sql - Regular expression in PostgreSQL LIKE clause -



sql - Regular expression in PostgreSQL LIKE clause -

i'm stuck simple regular expression. not sure i'm missing. little rusty on regex skills.

the look i'm trying match is:

select * table value '00[1-9]%' -- (third character should not 0)

so should match '0090d0df143a' (format: text) it's not!

like @a_horse commented, utilize regular look operator ~. there's more. if that's want:

(third character should not 0)

i suggest:

select * tbl value ~ '^00[^0]'

^ .. match @ start of string (your look can match @ any position in string). [^0] .. character class matching any character not '0'.

or better, yet:

select * tbl value '00%' -- starting '00' , value !~ '^..0' -- 3rd character not '0'

why? like not powerful, typically much faster regular expressions. it's substantially faster narrow downwards set of candidates inexpensive like look first.

more importantly, postgres can utilize simple indexes left-anchored expressions value '00%' (important big tables), while might not work complex regular expression. latest version of postgres can utilize indexes simple regular expressions, might work example. details: difference between , ~ in postgres

sql regex postgresql pattern-matching

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -