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

Function bitStringToCast

transpiler/transform/literals.go:95–115  ·  view source on GitHub ↗

bitStringToCast converts a pg_query bit-string value ("b101" / "B101") to a '101'::BIT TypeCast node. Returns nil for hex bit-strings (X'..') or anything it does not recognize, leaving the original node untouched.

(bsval string)

Source from the content-addressed store, hash-verified

93// '101'::BIT TypeCast node. Returns nil for hex bit-strings (X'..') or anything
94// it does not recognize, leaving the original node untouched.
95func bitStringToCast(bsval string) *pg_query.Node {
96 if len(bsval) < 1 {
97 return nil
98 }
99 switch bsval[0] {
100 case 'b', 'B':
101 bits := bsval[1:]
102 if bits == "" {
103 return nil
104 }
105 return &pg_query.Node{Node: &pg_query.Node_TypeCast{TypeCast: &pg_query.TypeCast{
106 Arg: strConst(bits),
107 TypeName: &pg_query.TypeName{
108 Names: []*pg_query.Node{{Node: &pg_query.Node_String_{String_: &pg_query.String{Sval: "BIT"}}}},
109 Typemod: -1,
110 },
111 }}}
112 }
113 // Hex bit-strings (X'..') are left as-is (out of scope).
114 return nil
115}
116
117// strConst builds an A_Const string-literal node.
118func strConst(s string) *pg_query.Node {

Callers 1

TransformMethod · 0.85

Calls 1

strConstFunction · 0.85

Tested by

no test coverage detected