@@ -29,11 +29,14 @@ import (
2929// initBinaryConcatenate registers the functions to the catalog.
3030func initBinaryConcatenate () {
3131 framework .RegisterBinaryFunction (framework .Operator_BinaryConcatenate , anytextcat )
32+ framework .RegisterBinaryFunction (framework .Operator_BinaryConcatenate , array_append )
33+ framework .RegisterBinaryFunction (framework .Operator_BinaryConcatenate , array_cat )
34+ framework .RegisterBinaryFunction (framework .Operator_BinaryConcatenate , array_prepend )
3235 framework .RegisterBinaryFunction (framework .Operator_BinaryConcatenate , byteacat )
3336 framework .RegisterBinaryFunction (framework .Operator_BinaryConcatenate , jsonb_concat )
3437 framework .RegisterBinaryFunction (framework .Operator_BinaryConcatenate , textanycat )
3538 framework .RegisterBinaryFunction (framework .Operator_BinaryConcatenate , textcat )
36- // TODO: array_append, array_cat, array_prepend, bitcat, tsquery_or, tsvector_concat
39+ // TODO: bitcat, tsquery_or, tsvector_concat
3740}
3841
3942// anytextcat_callable is the callable logic for the anytextcat function.
@@ -55,6 +58,65 @@ var anytextcat = framework.Function2{
5558 Callable : anytextcat_callable ,
5659}
5760
61+ // array_append represents the PostgreSQL function of the same name, taking the same parameters.
62+ var array_append = framework.Function2 {
63+ Name : "array_append" ,
64+ Return : pgtypes .AnyArray , // TODO: should be anycompatiblearray
65+ Parameters : [2 ]* pgtypes.DoltgresType {pgtypes .AnyArray , pgtypes .AnyElement }, // TODO: should be anycompatiblearray, anycompatible
66+ Strict : false ,
67+ Callable : func (ctx * sql.Context , paramsAndReturn [3 ]* pgtypes.DoltgresType , val1 any , val2 any ) (any , error ) {
68+ if val1 == nil {
69+ return []any {val2 }, nil
70+ }
71+ array := val1 .([]any )
72+ returnArray := make ([]any , len (array )+ 1 )
73+ copy (returnArray , array )
74+ returnArray [len (returnArray )- 1 ] = val2
75+ return returnArray , nil
76+ },
77+ }
78+
79+ // array_cat represents the PostgreSQL function of the same name, taking the same parameters.
80+ var array_cat = framework.Function2 {
81+ Name : "array_cat" ,
82+ Return : pgtypes .AnyArray , // TODO: should be anycompatiblearray
83+ Parameters : [2 ]* pgtypes.DoltgresType {pgtypes .AnyArray , pgtypes .AnyArray }, // TODO: should be anycompatiblearray, anycompatiblearray
84+ Strict : false ,
85+ Callable : func (ctx * sql.Context , paramsAndReturn [3 ]* pgtypes.DoltgresType , val1 any , val2 any ) (any , error ) {
86+ if val1 == nil && val2 == nil {
87+ return nil , nil
88+ } else if val1 == nil {
89+ return val2 , nil
90+ } else if val2 == nil {
91+ return val1 , nil
92+ }
93+
94+ array1 := val1 .([]any )
95+ array2 := val2 .([]any )
96+
97+ // Concatenate the arrays
98+ result := make ([]any , len (array1 )+ len (array2 ))
99+ copy (result , array1 )
100+ copy (result [len (array1 ):], array2 )
101+
102+ return result , nil
103+ },
104+ }
105+
106+ // array_prepend represents the PostgreSQL function of the same name, taking the same parameters.
107+ var array_prepend = framework.Function2 {
108+ Name : "array_prepend" ,
109+ Return : pgtypes .AnyArray , // TODO: should be anycompatiblearray
110+ Parameters : [2 ]* pgtypes.DoltgresType {pgtypes .AnyElement , pgtypes .AnyArray }, // TODO: should be anycompatible, anycompatiblearray
111+ Strict : false ,
112+ Callable : func (ctx * sql.Context , paramsAndReturn [3 ]* pgtypes.DoltgresType , val1 any , val2 any ) (any , error ) {
113+ if val2 == nil {
114+ return []any {val1 }, nil
115+ }
116+ return append ([]any {val1 }, val2 .([]any )... ), nil
117+ },
118+ }
119+
58120// byteacat_callable is the callable logic for the byteacat function.
59121func byteacat_callable (ctx * sql.Context , paramsAndReturn [3 ]* pgtypes.DoltgresType , val1 any , val2 any ) (any , error ) {
60122 v1 := val1 .([]byte )
0 commit comments