MCPcopy Create free account
hub / github.com/bytebase/bytebase / findLimitInsertPosition

Function findLimitInsertPosition

backend/plugin/db/pg/query.go:282–302  ·  view source on GitHub ↗

findLimitInsertPosition returns the byte offset where " LIMIT N" should be inserted, and whether the insertion is before a locking clause (FOR UPDATE/SHARE).

(sel *ast.SelectStmt)

Source from the content-addressed store, hash-verified

280// findLimitInsertPosition returns the byte offset where " LIMIT N" should be inserted,
281// and whether the insertion is before a locking clause (FOR UPDATE/SHARE).
282func findLimitInsertPosition(sel *ast.SelectStmt) (int, bool) {
283 // LIMIT must appear before FOR UPDATE/SHARE.
284 if sel.LockingClause != nil {
285 span := ast.ListSpan(sel.LockingClause)
286 if span.Start > 0 {
287 return span.Start, true
288 }
289 }
290
291 // Otherwise insert at SelectStmt.Loc.End (after everything, including outer parens).
292 // For CTE queries, omni may report SelectStmt.Loc.End before the outer ORDER BY,
293 // so account for the sort clause explicitly.
294 end := sel.Loc.End
295 if span := ast.ListSpan(sel.SortClause); span.End > end {
296 end = span.End
297 }
298 if end <= 0 {
299 return 0, false
300 }
301 return end, false
302}
303
304// extractIntFromNode extracts an integer value from a LIMIT/OFFSET node.
305func extractIntFromNode(node ast.Node) int {

Callers 1

rewriteSelectLimitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected