dataengref migrate

Home / SQL Server

SQL Server PATINDEX in Snowflake, Databricks and BigQuery

PATINDEX takes a LIKE pattern with % and [] wildcards. The targets use REGEXP_INSTR with a regular expression, so the pattern itself must be rewritten.

SQL Server function: PATINDEX('%pattern%', expression) · SQL Server docs

Equivalents

TargetSupportSyntaxNotesSource
SnowflakeRewriteREGEXP_INSTR(subject, pattern)Returns 0 when there is no match.Snowflake docs
DatabricksRewriteregexp_instr(str, regexp)Databricks SQL and Databricks Runtime 11.3 LTS and above.Databricks docs
BigQueryRewriteREGEXP_INSTR(source_value, regexp)Returns 0 when there is no match.BigQuery docs

Behavior differences to check

Examples

Position of the first digit

SQL Server
SELECT PATINDEX('%[0-9]%', code) AS first_digit FROM products;
Snowflake
SELECT REGEXP_INSTR(code, '[0-9]') AS first_digit FROM products;
Databricks
SELECT regexp_instr(code, '[0-9]') AS first_digit FROM products;
BigQuery
SELECT REGEXP_INSTR(code, r'[0-9]') AS first_digit FROM products;

Other SQL Server functions

Last checked: · Paste a whole query into the SQL checker to find every function that needs a change.