user3438030
user3438030

Reputation: 49

What does ~ ‘^[0-9]+$’ mean in PostgreSQL

I’m trying to understand what ~ '^[0-9]+$' means. Would it be any integer that contains 0-9? Or doesn’t contain 0-9?

Is the ~ equivalent to LIKE in MS SQL?

Upvotes: 2

Views: 8061

Answers (1)

wumpz
wumpz

Reputation: 9151

Looking at https://www.postgresql.org/docs/9.6/static/functions-matching.html#FUNCTIONS-POSIX-TABLE, you will find, that ~ means:

"Matches regular expression, case sensitive"

'^[0-9]+$' is a regular expression, with:

  • ^: from string start
  • $: til string end
  • [0-9]+: one or more digits.

I don't know how you define integer, but e.g. '0000' is matched as well.

SqlServer does not support complete regular expression syntax out of the box and like does not handle regular expressions in PostgreSQL as well, therefore it is not equivalent to ~.

Upvotes: 3

Related Questions