INSERT

functionsupportedCore SQL functions

docs.snowflake.com ↗

String & binary functions

Replaces a substring of the specified length, starting at the specified position, with a new string or binary value. This function should not be confused with the INSERT DML command.

Syntax

INSERT( <base_expr>, <pos>, <len>, <insert_expr> )

Parameters

NameRequiredDescription
base_exprrequiredThe string or BINARY expression for which you want to insert/replace characters.
posrequiredThe offset at which to start inserting characters. This is 1-based, not 0-based. In other words, the first character in the string is considered to be at position 1, not position 0. For example, to insert at the beginning of the string, set pos to 1. Valid values are between 1 and one more than the length of the string (inclusive). Setting pos to one more than the length of the string makes the operation equivalent to an append. (This also requires that the len parameter be 0 because you should not try to delete any characters past the last character.)
lenrequiredThe number of characters (starting at pos) that you want to replace. Valid values range from 0 to the number of characters between pos and the end of the string. If this is 0, it means add the new characters without deleting any existing characters.
insert_exprrequiredThe string to insert into the base_expr. If this string is empty, and if len is greater than zero, then effectively the operation becomes a delete (some characters are deleted, and none are added).

Returns

Returns a string or BINARY that is equivalent to making a copy of base_expr, deleting len characters starting at pos, and then inserting insert_expr at pos. Note that the original input base_expr is not changed; the function returns a separate (modified) copy.

Usage notes