+1 vote
in Databases by (66.6k points)
I want to select all rows where the column value starts with "X7", followed by at least one digit between 1 and 9, then followed by zero or more digits (0-9), i.e., something like X7[1-9][0-9]*. Can I use regular expression like syntax in the WHERE clause for PostgreSQL?

1 Answer

+3 votes
by (365k points)
selected by
 
Best answer

Yes, PostgreSQL allows regular expressions in the WHERE clause. Here is an example using your given regular expression.

The following SQL is based on PostgreSQL:

SELECT *
FROM table_name
WHERE column_name ~ '^X7[1-9][0-9]*'; 

In the above query, you can replace table_name with your table name and column_name with the column you want to choose.

Related questions

+3 votes
1 answer
+3 votes
1 answer
+3 votes
1 answer
+2 votes
1 answer

...