From f9dff0b0eb9d459bd65f6748c44aced131de697e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Mon, 29 Apr 2024 21:41:09 +0000 Subject: [PATCH] rewrite limit --- nexus/peer-mysql/src/ast.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nexus/peer-mysql/src/ast.rs b/nexus/peer-mysql/src/ast.rs index 35d0ae53f8..de1b3ae9dd 100644 --- a/nexus/peer-mysql/src/ast.rs +++ b/nexus/peer-mysql/src/ast.rs @@ -1,6 +1,6 @@ use std::ops::ControlFlow; -use sqlparser::ast::{visit_relations_mut, Query}; +use sqlparser::ast::{visit_relations_mut, Expr, Query}; pub fn rewrite_query(peername: &str, query: &mut Query) { visit_relations_mut(query, |table| { @@ -10,4 +10,9 @@ pub fn rewrite_query(peername: &str, query: &mut Query) { } ControlFlow::<()>::Continue(()) }); + + // postgres_fdw sends `limit 1` as `limit 1::bigint` which mysql chokes on + if let Some(Expr::Cast { expr, .. }) = &query.limit { + query.limit = Some((**expr).clone()); + } }