@@ -536,14 +536,12 @@ final class QueryViewModel {
536 /// query text was replaced (i.e. the user hadn't customized it).
536 /// query text was replaced (i.e. the user hadn't customized it).
537 @discardableResult
537 @discardableResult
538 func setDefaultQuery(stream: String, previousStream: String? = nil) -> Bool {
538 func setDefaultQuery(stream: String, previousStream: String? = nil) -> Bool {
539− // Replace the query if it's empty or still matches the auto-generated
539+ // Always replace when switching streams — the previous query (whether
540− // default for the previous stream. If the user edited the SQL, keep it.
540+ // auto-generated or from a saved filter) belongs to the old stream.
541+ // Only preserve the query when no stream change occurred (e.g. onAppear).
541 let shouldReplace: Bool
542 let shouldReplace: Bool
542− if sqlQuery.isEmpty {
543+ if sqlQuery.isEmpty || previousStream != nil {
543 shouldReplace = true
544 shouldReplace = true
544− } else if let prev = previousStream {
545− let prevPrefix = "SELECT * FROM \(Self.escapeSQLIdentifier(prev))"
546− shouldReplace = sqlQuery.hasPrefix(prevPrefix)
548 shouldReplace = false
546 shouldReplace = false