SQL Reference
Tuple Functions and Operators
tuple functions function syntax purpose constructor tuple<\<type1,type2, …, typen>>(e1, e2, …, en) construct a tuple given elements null is also supported as an element implicit constructor tuple(e1, e2, …, en) construct a tuple with the specified elements types of the tuple are inferred from the inner elements convert tuple to string char(tuple) converts a tuple to its string representation convert string to tuple string to tuple(str, format) converts the string representation of a tuple (e g , 'tuple<\<int,bigint,char>>(1,2,null)') into a tuple tuple casting cast to tuple(tuple, format) converts a tuple into another tuple of a different type (e g , cast to tuple(tuple<\<int,int>>(1,2), 'tuple(bigint,double)')) tuple function examples function sql statement result type constructor tuple<\<int,bigint>>(1,2) tuple holding int(1) and bigint(2) type constructor for array of tuples tuple<\<int,bigint>>\[]\(tuple<\<int,bigint>>(1,2), tuple<\<int,bigint>>(3,4)) array holding 2 tuples \[(1,2), (1,2)] char(\<tuple value>) char(tuple<\<int,bigint>>(1,2)) 'tuple<\<int,bigint>>(1,2)' string to array string to array('tuple<\<int,bigint>>\[tuple<\<int,bigint>>(1,2)]','array(tuple(int,bigint))') tuple<\<int,bigint>>\[tuple<\<int,bigint>>(1,2)] tuple operators operator syntax description access operator tuple\[element index] returns the element stored in the specified index position the index starts at 1 access out of bounds returns a null slice operator tuple\[left index\ right index] returns the subtuple ranging from left index to right index inclusive the index starts at 1 about the tuple slice operator each index starts at 1 if the tuple is null or either index value is null, the result of the slicing is null if you omit the left index, it is equivalent to using 1 if you omit the right index, it is equivalent to len(tuple) if you omit both, it returns the full tuple tuple<\<int,int,int>>(1, 2, 3)\[ ] is equivalent to tuple<\<int,int,int>>(1, 2, 3) values below zero for the left index convert to 1 , and values beyond the tuple length for the right index convert to len(tuple) tupleval\[ 1 4] is equivalent to tupleval\[1 4] , and tuple<\<int,int,int>>(1, 2, 3)\[1 6] is equivalent to tuple<\<int,int,int>>(1, 2, 3)\[1 3] ranges completely out of tuple bounds throw an invalid argument error, e g , tuple<\<int,int>>(1,2)\[4 5] sequential slices slice each dimension of tuples tuple<\<tuple<\<int,int,int>>,tuple<\<int,int,int>>>>(tuple<\<int,int,int>>(1, 2, 3), tuple<\<int,int,int>>(4, 5, 6))\[1 1]\[2 3] = tuple<\<tuple<\<int,int>>>>(tuple<\<int,int>>(2, 3)) more than n sequential slices of an n dimensional tuple, for example, three sequential slices on a two dimensional tuple throw an error tuple<\<int>>(1)\[ ]\[ ] you cannot combine slicing with the access operator if you attempt such a combination, any access operator \[n] converts to \[ n] tupleval\[4]\[1 6] = tupleval\[ 4]\[1 6] slicing with non constant indixes throws an error slicing a tuple of arrays such as tuple<\<int\[],double\[]>>(int\[1,2,3],double\[4,5,6])\[1 1]\[2 3] slices \[1 1] on the tuple and \[2 3] on the resulting inner arrays, resulting in tuple<\<int\[]>>(int\[2,3]) slicing a tuple with a mix of containers and primitives such as tuple<\<int,int\[]>>(1,int\[1,2,3]) throws an error if, at any given depth, the slice is not valid for one or more elements slicing the tuple with \[ ]\[2 3] fails because you cannot slice an integer, and the resultant tuple from \[ ] includes an integer however, slicing with \[2 2]\[2 3] returns tuple<\<int\[]>>(int\[2,3]) because the tuple resulting from the \[2 2] slice contains only elements that the next slice range can sliced operator examples operator sql predicate result access operator tuple<\<char,bigint>>('sql',2)\[1] 'sql' access operator tuple<\<char,bigint>>('sql',2)\[2] null slice operator tuple<\<char,bigint,bigint>>('sql',1,2)\[1 2] tuple<\<char,bigint>>('sql',1) related links docid 89kk83 gif3icefcy1kuw docid\ dwjpaeks9otz2u sav2lj docid\ e2c2vckzh8dfsbp1wngpr docid\ ogtviwl gtbgv0chhrh 3 docid 4ycq1d8tkfmlsacorynf6