PostgreSQLdata extraction

Extract Phone Number from Text Column in PostgreSQL

Use PostgreSQL regexp_matches to extract phone numbers from text fields. SQL examples for phone number extraction.

The Regex Pattern

Regex pattern

\+?[1-9]\d{1,14}

Use this pattern with PostgreSQL's ~ operator.

PostgreSQL SQL Example

-- Use regexp_matches in PostgreSQL to extract phone numbers embedded in free-text columns like notes or addresses
SELECT *
FROM your_table
WHERE your_column ~ '\\+?[1-9]\\d{1,14}';

How This Works

Use regexp_matches in PostgreSQL to extract phone numbers embedded in free-text columns like notes or addresses. The regex pattern is used with PostgreSQL's ~ operator to filter rows at the database level.

Using regex directly in SQL is efficient for use cases like data extraction โ€” it avoids loading data into application memory just to filter it with a regex.

Need a custom SQL + Regex query?

Describe your specific use case in plain English. RegSQL generates the exact PostgreSQL query with the right regex pattern for your schema.

Related SQL Patterns