MCPcopy Index your code
hub / github.com/bytebase/bytebase / parseSelectBody

Function parseSelectBody

backend/plugin/parser/pg/query_span_loader_builders.go:181–198  ·  view source on GitHub ↗

parseSelectBody parses a SQL string expected to be a single SELECT statement and returns the *ast.SelectStmt. Rejects empty input, multiple statements, and non-SELECT top-level nodes. Unwraps a RawStmt wrapper if ParsePg returns one.

(sql string)

Source from the content-addressed store, hash-verified

179// statements, and non-SELECT top-level nodes. Unwraps a RawStmt wrapper if
180// ParsePg returns one.
181func parseSelectBody(sql string) (*ast.SelectStmt, error) {
182 stmts, err := ParsePg(sql)
183 if err != nil {
184 return nil, errors.Wrap(err, "parse")
185 }
186 if len(stmts) != 1 {
187 return nil, errors.Errorf("expected 1 statement, got %d", len(stmts))
188 }
189 node := stmts[0].AST
190 if raw, ok := node.(*ast.RawStmt); ok {
191 node = raw.Stmt
192 }
193 sel, ok := node.(*ast.SelectStmt)
194 if !ok {
195 return nil, errors.Errorf("expected SelectStmt, got %T", node)
196 }
197 return sel, nil
198}
199
200// parseFunctionSignatureArgTypes extracts the comma-separated argument types
201// from a signature like "fn(integer, text)" or "fn(numeric(10,2), boolean)".

Callers 3

buildViewStmtFunction · 0.85
buildCreateTableAsStmtFunction · 0.85

Calls 2

ParsePgFunction · 0.85
ErrorfMethod · 0.80

Tested by 1