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

Method parseForSystemTimeClause

pkg/sql/parser/mariadb.go:264–330  ·  view source on GitHub ↗

parseForSystemTimeClause parses the FOR SYSTEM_TIME clause that follows a table reference. The caller has already consumed FOR.

()

Source from the content-addressed store, hash-verified

262// parseForSystemTimeClause parses the FOR SYSTEM_TIME clause that follows a table reference.
263// The caller has already consumed FOR.
264func (p *Parser) parseForSystemTimeClause() (*ast.ForSystemTimeClause, error) {
265 if !strings.EqualFold(p.currentToken.Token.Value, "SYSTEM_TIME") {
266 return nil, fmt.Errorf("expected SYSTEM_TIME after FOR, got %q", p.currentToken.Token.Value)
267 }
268 sysTimePos := p.currentLocation() // position of SYSTEM_TIME token
269 p.advance()
270
271 clause := &ast.ForSystemTimeClause{}
272 clause.Pos = sysTimePos
273 word := strings.ToUpper(p.currentToken.Token.Value)
274
275 switch word {
276 case "AS":
277 p.advance()
278 if !strings.EqualFold(p.currentToken.Token.Value, "OF") {
279 return nil, fmt.Errorf("expected OF after AS, got %q", p.currentToken.Token.Value)
280 }
281 p.advance()
282 expr, err := p.parseTemporalPointExpression()
283 if err != nil {
284 return nil, err
285 }
286 clause.Type = ast.SystemTimeAsOf
287 clause.Point = expr
288 case "BETWEEN":
289 p.advance()
290 // Use parsePrimaryExpression to avoid consuming AND as a binary logical operator.
291 start, err := p.parseTemporalPointExpression()
292 if err != nil {
293 return nil, err
294 }
295 if !strings.EqualFold(p.currentToken.Token.Value, "AND") {
296 return nil, fmt.Errorf("expected AND in FOR SYSTEM_TIME BETWEEN, got %q", p.currentToken.Token.Value)
297 }
298 p.advance()
299 end, err := p.parseTemporalPointExpression()
300 if err != nil {
301 return nil, err
302 }
303 clause.Type = ast.SystemTimeBetween
304 clause.Start = start
305 clause.End = end
306 case "FROM":
307 p.advance()
308 start, err := p.parseTemporalPointExpression()
309 if err != nil {
310 return nil, err
311 }
312 if !strings.EqualFold(p.currentToken.Token.Value, "TO") {
313 return nil, fmt.Errorf("expected TO in FOR SYSTEM_TIME FROM, got %q", p.currentToken.Token.Value)
314 }
315 p.advance()
316 end, err := p.parseTemporalPointExpression()
317 if err != nil {
318 return nil, err
319 }
320 clause.Type = ast.SystemTimeFromTo
321 clause.Start = start

Callers 2

parseJoinedTableRefMethod · 0.95

Calls 4

currentLocationMethod · 0.95
advanceMethod · 0.95
ErrorfMethod · 0.65

Tested by

no test coverage detected