Re: Array, ANY and Regular Expressions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Stefan 'Kaishakunin' Schumacher" <stefan(at)net-tex(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Array, ANY and Regular Expressions
Date: 2008-08-23 16:22:19
Message-ID: 4112.1219508539@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Stefan 'Kaishakunin' Schumacher" <stefan(at)net-tex(dot)de> writes:
> I have a table with an array column (tags text[]) which I want to
> select from via ANY and RegExes.

> SELECT tags from zettelkasten where 'Sozialpsychologie' ~* any(tags) order by
> ident;

Did you look at the matches? I suspect this isn't behaving even
remotely the way you want, because ~* expects the pattern operand
on the right.

Since there's no SQL syntax with ANY() on the left of the comparison
operator, what you'd need to do to make this work is invent a "reverse
regex" operator that switches its arguments. That'd be pretty trivial
to do with a one-line plpgsql function under it. (I'm not sure what
performance would be like though; as the table grows you might find
yourself needing to change the reversing function to C.)

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2008-08-23 16:28:31 psql vs. pgadmin3 was:can't get UPDATE ... RETURNING ... INTO ... to compile successfully
Previous Message Tom Lane 2008-08-23 16:12:57 Re: [GENERAL] Surprising syntax error