Teradata Package for Python Function Reference | 20.00 - array_insert - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- VMware
- Enterprise
- IntelliFlex
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.11
- Published
- August 2026
- ft:locale
- en-US
- ft:lastEdition
- 2026-08-13
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.array_insert = array_insert(self, index, element)
- DESCRIPTION:
Insert an element at the specified index in the array.
PARAMETERS:
index:
Required Argument.
Specifies the index (1-based) where to insert the element.
Types: int OR ColumnExpression
element:
Required Argument.
Specifies the element to insert.
Types: ColumnExpression OR Python literal
RETURNS:
ColumnExpression
EXAMPLES:
>>> from teradataml import *
>>> load_example_data("array", "array_table")
# Create a DataFrame on 'array_table'.
>>> df = DataFrame("array_table")
>>> df
arr1 arr2 arr3
id
1 (10,20,30,40,50) (23,200,215,40,21) ('ab','bc','cd','ab','ef')
4 (180,28,38,48,58) (30,NULL,NULL,250,27) ('mn','no',NULL,'op','pq')
2 (150,25,35,45,55) (28,50,95,90,26) ('xy','yz','za','ab','xy')
6 (16,261,36,46,56) (29,170,160,46,25) ('uv','xy','ab','xy','yz')
3 (12,22,320,42,52) (25,22,140,200,23) ('pq','ab','ab','st','tu')
5 (14,24,34,44,54) (26,NULL,NULL,180,24) ('ij','jk',NULL,'kl','lm')
# Example 1: Insert element 'txt' at index 3 in array column 'arr3'.
>>> res = df.assign(modified_arr = df.arr3.array_insert(index=3, element="txt"))
>>> res
arr1 arr2 arr3 modified_arr
id
3 (12,22,320,42,52) (25,22,140,200,23) ('pq','ab','ab','st','tu') ('pq','ab','txt','ab','st','tu')
1 (10,20,30,40,50) (23,200,215,40,21) ('ab','bc','cd','ab','ef') ('ab','bc','txt','cd','ab','ef')
2 (150,25,35,45,55) (28,50,95,90,26) ('xy','yz','za','ab','xy') ('xy','yz','txt','za','ab','xy')
5 (14,24,34,44,54) (26,NULL,NULL,180,24) ('ij','jk',NULL,'kl','lm') ('ij','jk','txt',NULL,'kl','lm')
6 (16,261,36,46,56) (29,170,160,46,25) ('uv','xy','ab','xy','yz') ('uv','xy','txt','ab','xy','yz')
4 (180,28,38,48,58) (30,NULL,NULL,250,27) ('mn','no',NULL,'op','pq') ('mn','no','txt',NULL,'op','pq')
# Example 2: Insert element from column 'id' at index specified in column 'idx' in array column 'arr3'.
>>> tdf = df.assign(idx=4)
>>> res = tdf.assign(modified_arr = tdf.arr2.array_insert(tdf.idx, tdf.id))
>>> res
arr1 arr2 arr3 idx modified_arr
id
2 (150,25,35,45,55) (28,50,95,90,26) ('xy','yz','za','ab','xy') 4 (28,50,95,2,90,26)
3 (12,22,320,42,52) (25,22,140,200,23) ('pq','ab','ab','st','tu') 4 (25,22,140,3,200,23)
6 (16,261,36,46,56) (29,170,160,46,25) ('uv','xy','ab','xy','yz') 4 (29,170,160,6,46,25)
4 (180,28,38,48,58) (30,NULL,NULL,250,27) ('mn','no',NULL,'op','pq') 4 (30,NULL,NULL,4,250,27)
1 (10,20,30,40,50) (23,200,215,40,21) ('ab','bc','cd','ab','ef') 4 (23,200,215,1,40,21)
5 (14,24,34,44,54) (26,NULL,NULL,180,24) ('ij','jk',NULL,'kl','lm') 4 (26,NULL,NULL,5,180,24)
# Example 3: Insert element at index 10 greater than array size in array column 'arr1'.
>>> res = df.assign(modified_arr = df.arr1.array_insert(index=10, element=999))
>>> res
arr1 arr2 arr3 modified_arr
id
5 (14,24,34,44,54) (26,NULL,NULL,180,24) ('ij','jk',NULL,'kl','lm') (14,24,34,44,54,NULL,NULL,NULL,NULL,999)
2 (150,25,35,45,55) (28,50,95,90,26) ('xy','yz','za','ab','xy') (150,25,35,45,55,NULL,NULL,NULL,NULL,999)
6 (16,261,36,46,56) (29,170,160,46,25) ('uv','xy','ab','xy','yz') (16,261,36,46,56,NULL,NULL,NULL,NULL,999)
1 (10,20,30,40,50) (23,200,215,40,21) ('ab','bc','cd','ab','ef') (10,20,30,40,50,NULL,NULL,NULL,NULL,999)
3 (12,22,320,42,52) (25,22,140,200,23) ('pq','ab','ab','st','tu') (12,22,320,42,52,NULL,NULL,NULL,NULL,999)
4 (180,28,38,48,58) (30,NULL,NULL,250,27) ('mn','no',NULL,'op','pq') (180,28,38,48,58,NULL,NULL,NULL,NULL,999)