MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / parseDescribeStatement

Method parseDescribeStatement

pkg/sql/parser/mysql.go:149–191  ·  view source on GitHub ↗

parseDescribeStatement parses DESCRIBE/DESC/EXPLAIN table_name

()

Source from the content-addressed store, hash-verified

147
148// parseDescribeStatement parses DESCRIBE/DESC/EXPLAIN table_name
149func (p *Parser) parseDescribeStatement() (ast.Statement, error) {
150 // For EXPLAIN SELECT ..., defer to parseStatement for the SELECT
151 // For DESCRIBE table_name, just parse the table name
152 if p.isType(models.TokenTypeSelect) {
153 // EXPLAIN SELECT ... - treat as describe with the query text
154 // For now, just skip to parse the select
155 p.advance()
156 stmt, err := p.parseSelectWithSetOperations()
157 if err != nil {
158 return nil, err
159 }
160 // Wrap in a describe
161 _ = stmt
162 desc := ast.GetDescribeStatement()
163 desc.TableName = "SELECT"
164 return desc, nil
165 }
166
167 // Snowflake: DESCRIBE TABLE <name>, DESCRIBE VIEW <name>, DESCRIBE STAGE
168 // <name>, etc. Also MySQL's DESCRIBE <db>.<table>. Accept and consume a
169 // leading object-kind keyword (TABLE, VIEW, DATABASE, SCHEMA) before the
170 // name so we don't fail on "DESCRIBE TABLE users".
171 if p.isType(models.TokenTypeTable) || p.isType(models.TokenTypeView) ||
172 p.isType(models.TokenTypeDatabase) ||
173 strings.EqualFold(p.currentToken.Token.Value, "SCHEMA") ||
174 strings.EqualFold(p.currentToken.Token.Value, "STAGE") ||
175 strings.EqualFold(p.currentToken.Token.Value, "STREAM") ||
176 strings.EqualFold(p.currentToken.Token.Value, "TASK") ||
177 strings.EqualFold(p.currentToken.Token.Value, "PIPE") ||
178 strings.EqualFold(p.currentToken.Token.Value, "FUNCTION") ||
179 strings.EqualFold(p.currentToken.Token.Value, "PROCEDURE") ||
180 strings.EqualFold(p.currentToken.Token.Value, "WAREHOUSE") {
181 p.advance()
182 }
183
184 name, err := p.parseQualifiedName()
185 if err != nil {
186 return nil, p.expectedError("table name")
187 }
188 desc := ast.GetDescribeStatement()
189 desc.TableName = name
190 return desc, nil
191}
192
193// parseReplaceStatement parses MySQL REPLACE INTO statement
194func (p *Parser) parseReplaceStatement() (ast.Statement, error) {

Callers 1

parseStatementMethod · 0.95

Calls 6

isTypeMethod · 0.95
advanceMethod · 0.95
parseQualifiedNameMethod · 0.95
expectedErrorMethod · 0.95
GetDescribeStatementFunction · 0.92

Tested by

no test coverage detected