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

Method createGetVariableSelect

transpiler/transform/setshow.go:608–640  ·  view source on GitHub ↗

createGetVariableSelect creates a SELECT getvariable('name') AS name statement

(paramName string)

Source from the content-addressed store, hash-verified

606 }
607
608 parts := make([]string, 0, len(stmt.Args))
609 for _, arg := range stmt.Args {
610 part, ok := searchPathValue(arg)
611 if !ok {
612 return "", false
613 }
614 parts = append(parts, part)
615 }
616
617 prefix := "SET search_path = "
618 if stmt.IsLocal {
619 prefix = "SET LOCAL search_path = "
620 }
621
622 value := strings.Join(parts, ",")
623 value = strings.ReplaceAll(value, "'", "''")
624 return prefix + "'" + value + "'", true
625}
626
627func searchPathValue(node *pg_query.Node) (string, bool) {
628 if node == nil {
629 return "", false
630 }
631
632 switch n := node.Node.(type) {
633 case *pg_query.Node_AConst:
634 if n.AConst == nil {
635 return "", false
636 }
637 if sval := n.AConst.GetSval(); sval != nil {
638 return sval.Sval, true
639 }
640 case *pg_query.Node_String_:
641 if n.String_ != nil {
642 return n.String_.Sval, true
643 }

Callers 1

TransformMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected