regex (not) matching null string - Mailing list pgsql-bugs

From David M. Kaplan
Subject regex (not) matching null string
Date
Msg-id 3D10F11C.9070606@ucdavis.edu
Whole thread Raw
Responses Re: regex (not) matching null string
Re: regex (not) matching null string
List pgsql-bugs
I have found that !~ and !~* do not match the null string even when one
would expect them to.  I am not sure if this is how it is supposed to
work or if this is an error.  If this is how it works, I can't figure
out where it is states in the documentation.

Let me give an example.  Suppose we have a table "t" that look as follows:

# SELECT * FROM t;
 n | s
---+---
 1 | a
 2 | b
 3 |
 4 | d
(4 rows)

Now consider the following query results:

# SELECT * FROM t where s ~* 'a';
 n | s
---+---
 1 | a
(1 row)

This works as expected (by me).

# SELECT * FROM t where s !~* 'a';
 n | s
---+---
 2 | b
 4 | d
(2 rows)

This is not what I would have expected.  Instead, I thought the result
would be:

# SELECT * FROM t where s !~* 'a';  --- This does not happen!!
 n | s
---+---
 2 | b
 3 |
 4 | d
(3 rows)

It seems to me that !~* should just be the inverse of ~*, but this does
not seem to be the case.

David

pgsql-bugs by date:

Previous
From: Попов Андрей
Date:
Subject: I have problem with pg_dump in PostgreSQL 7.1.2
Next
From: Stephan Szabo
Date:
Subject: Re: WHERE =NULL malfunction in release 7.2