MCPcopy
hub / github.com/sqlc-dev/sqlc / parseColName

Function parseColName

internal/engine/postgresql/parse.go:111–134  ·  view source on GitHub ↗
(node *nodes.Node)

Source from the content-addressed store, hash-verified

109}
110
111func parseColName(node *nodes.Node) (*ast.ColumnRef, *ast.TableName, error) {
112 switch n := node.Node.(type) {
113 case *nodes.Node_List:
114 parts := stringSlice(n.List)
115 var tbl *ast.TableName
116 var ref *ast.ColumnRef
117 switch len(parts) {
118 case 2:
119 tbl = &ast.TableName{Name: parts[0]}
120 ref = &ast.ColumnRef{Name: parts[1]}
121 case 3:
122 tbl = &ast.TableName{Schema: parts[0], Name: parts[1]}
123 ref = &ast.ColumnRef{Name: parts[2]}
124 case 4:
125 tbl = &ast.TableName{Catalog: parts[0], Schema: parts[1], Name: parts[2]}
126 ref = &ast.ColumnRef{Name: parts[3]}
127 default:
128 return nil, nil, fmt.Errorf("column specifier %q is not the proper format, expected '[catalog.][schema.]colname.tablename'", strings.Join(parts, "."))
129 }
130 return ref, tbl, nil
131 default:
132 return nil, nil, fmt.Errorf("parseColName: unexpected node type: %T", n)
133 }
134}
135
136func joinNodes(list []*nodes.Node, sep string) string {
137 return strings.Join(stringSliceFromNodes(list), sep)

Callers 1

translateFunction · 0.85

Calls 2

stringSliceFunction · 0.70
JoinMethod · 0.45

Tested by

no test coverage detected