You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LIMIT ... OFFSET ... does not work with sqlpage variables in MySQL #1154
I can't use variables defined with "SET" in offset in MariaDB.
error returned from database: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CAST(? AS CHAR) OFFSET CAST(? AS CHAR)' at line 1
I'm defining the variables like this:
set limite =10;
set offset = (COALESCE($page, 1) -1) * $limite;
And then I'm trying to use them in the consultation:
Most databases allow arbitrary expressions in limit clauses, but unfortunately mysql doesn't
LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants, with these exceptions:
Within prepared statements, LIMIT parameters can be specified using ? placeholder markers.
changed the title [-]LIMIT ... OFFSET ... does not work with sqlpage variables[/-][+]LIMIT ... OFFSET ... does not work with sqlpage variables in MySQL[/+]on Dec 18, 2025
Let's leave this open, it's still a usability issue. If SQLPage were smart enough to omit the cast to a string here the obvious limit ... offset ... syntax would work out of the box
Activity
[-]OFFSET not work[/-][+]LIMIT ... OFFSET ... does not work with sqlpage variables[/+]lovasoa commentedon Dec 18, 2025
Most databases allow arbitrary expressions in limit clauses, but unfortunately mysql doesn't
What you canndo to work around the problem is use row_number:
[-]LIMIT ... OFFSET ... does not work with sqlpage variables[/-][+]LIMIT ... OFFSET ... does not work with sqlpage variables in MySQL[/+]srcarvalho12 commentedon Dec 18, 2025
I understand! Thank you for your reply, I'll look into it!
lovasoa commentedon Dec 21, 2025
Let's leave this open, it's still a usability issue. If SQLPage were smart enough to omit the cast to a string here the obvious limit ... offset ... syntax would work out of the box
srcarvalho12 commentedon Dec 21, 2025
That's fine! No problem!
docs(changelog): add issue references for variable cast fix
docs(changelog): add issue references for variable cast fix
test: simplify variable cast tests and add focused repros for #516 and …
lovasoa commentedon Aug 22, 2026
Hi ! I know I'm late, but I have a planned fix in #1397 that you can try !
Stop casting variables to TEXT on PostgreSQL, MySQL and SQL Server (s…