dataengref migrate

Home / SQL Server

SQL Server STUFF in Snowflake, Databricks and BigQuery

Snowflake INSERT and Databricks overlay do what STUFF does. BigQuery has no single function; build the result with SUBSTR and CONCAT. STUFF is also used with FOR XML PATH to concatenate rows, which should become a string aggregate instead.

SQL Server function: STUFF(character_expression, start, length, replace_with_expression) · SQL Server docs

Equivalents

TargetSupportSyntaxNotesSource
SnowflakeDifferent nameINSERT(base_expr, pos, len, insert_expr)Same argument order as STUFF. Returns NULL if any argument is NULL.Snowflake docs
DatabricksDifferent nameoverlay(input PLACING replace FROM pos FOR len)Also callable as overlay(input, replace, pos, len); note that replace comes before pos.Databricks docs
BigQueryRewriteCONCAT(SUBSTR(s, 1, pos - 1), replacement, SUBSTR(s, pos + len))No STUFF or INSERT string function.BigQuery docs

Behavior differences to check

Examples

Mask the middle of a phone number

SQL Server
SELECT STUFF(phone, 4, 4, '****') AS masked FROM customers;
Snowflake
SELECT INSERT(phone, 4, 4, '****') AS masked FROM customers;
Databricks
SELECT overlay(phone PLACING '****' FROM 4 FOR 4) AS masked FROM customers;
BigQuery
SELECT CONCAT(SUBSTR(phone, 1, 3), '****', SUBSTR(phone, 8)) AS masked FROM customers;

Other SQL Server functions

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