Using caret (^) for pattern list matching negation in SIMILAR TO and ~ queries in Redshift

dba.stackexchange https://dba.stackexchange.com/questions/285071

  •  15-03-2021
  •  | 
  •  

Domanda

I'm quite new to using POSIX regex in Redshift. I honestly think that this pattern must be compatible.

[^A-Za-z0-9\\.\\,-]+

However, as I've tried a query like this

SELECT * FROM my_table WHERE string_column ~ '[^A-Za-z0-9\\.\\,-]+';

it gives me a result that doesn't match with what I like, and it seems to be considering the caret as a character literal. I've also tried using [^[:alnum:]] to no avail. What could be the reason why this happens? Did I input something wrong, or is this a limitation within Redshift or the JDBC drivers?

I'm currently running queries through JetBrains DataGrip (latest version) and running it with the latest Amazon Redshift JDBC driver.

È stato utile?

Soluzione

The problem with how I used this pattern is how I wrongly tried to add characters after the - character. Basically, Redshift does support the use of carets for pattern list matching negation. So this

[^A-Za-z0-9\\.\\,-]+

should not cause any problems, but

[^A-Za-z0-9\\.\\,-\\s]+

might cause problems because it might assume a range lookup instead for looking for both - and whitespace characters.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange
scroll top