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)
| 93 | // '101'::BIT TypeCast node. Returns nil for hex bit-strings (X'..') or anything |
| 94 | // it does not recognize, leaving the original node untouched. |
| 95 | func 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. |
| 118 | func strConst(s string) *pg_query.Node { |