MCPcopy Create free account
hub / github.com/PostHog/duckgres / pgArrayLiteralToArrayExpr

Function pgArrayLiteralToArrayExpr

transpiler/transform/typecast.go:608–639  ·  view source on GitHub ↗

pgArrayLiteralToArrayExpr converts a literal Postgres array text form (e.g. '{1,2,3}', '{a,b}', '{1,NULL,3}', '{"a,b",c}') into a DuckDB ARRAY[...] expression node. Each element becomes a single-quoted string A_Const (or a NULL const for the bare NULL token); the surrounding ::TARGET[] cast then app

(arg *pg_query.Node)

Source from the content-addressed store, hash-verified

606// applies the element type. Returns nil (leave untransformed) for non-literal
607// args or nested/multi-dimensional literals.
608func pgArrayLiteralToArrayExpr(arg *pg_query.Node) *pg_query.Node {
609 if arg == nil {
610 return nil
611 }
612 ac := arg.GetAConst()
613 if ac == nil {
614 return nil
615 }
616 sval := ac.GetSval()
617 if sval == nil {
618 return nil
619 }
620 elems, ok := parsePGArrayLiteral(sval.Sval)
621 if !ok {
622 return nil
623 }
624 nodes := make([]*pg_query.Node, 0, len(elems))
625 for _, e := range elems {
626 if e.isNull {
627 nodes = append(nodes, &pg_query.Node{
628 Node: &pg_query.Node_AConst{AConst: &pg_query.A_Const{Isnull: true}},
629 })
630 continue
631 }
632 nodes = append(nodes, stringConstNode(e.val))
633 }
634 return &pg_query.Node{
635 Node: &pg_query.Node_AArrayExpr{
636 AArrayExpr: &pg_query.A_ArrayExpr{Elements: nodes},
637 },
638 }
639}
640
641type pgArrayElem struct {
642 val string

Callers 1

walkAndTransformMethod · 0.85

Calls 2

parsePGArrayLiteralFunction · 0.85
stringConstNodeFunction · 0.85

Tested by

no test coverage detected