getStatementWithResultLimit returns the statement with LIMIT clause if not exists.
(statement string, limit int)
| 214 | |
| 215 | // getStatementWithResultLimit returns the statement with LIMIT clause if not exists. |
| 216 | func getStatementWithResultLimit(statement string, limit int) string { |
| 217 | stmt, err := getStatementWithResultLimitInline(statement, limit) |
| 218 | if err != nil { |
| 219 | slog.Error("fail to add limit clause", slog.String("statement", statement), log.BBError(err)) |
| 220 | // Fallback to CTE approach for problematic queries |
| 221 | return fmt.Sprintf("WITH result AS (\n%s\n) SELECT * FROM result LIMIT %d;", util.TrimStatement(statement), limit) |
| 222 | } |
| 223 | return stmt |
| 224 | } |
| 225 | |
| 226 | func getStatementWithResultLimitInline(statement string, limitCount int) (string, error) { |
| 227 | if strings.TrimSpace(statement) == "" { |