Closed
Description
Migrated issue, originally created by Michael Bayer (@zzzeek)
e.g. firebird, sql server, others:
from sqlalchemy import *
from sqlalchemy.sql import column, literal
s1 = select([column('x')]).select_from('a').limit(5).as_scalar()
s2 = select([s1]).limit(10)
from sqlalchemy.engine import default
from sqlalchemy.sql import compiler
class MyCompiler(compiler.SQLCompiler):
def get_select_precolumns(self, select):
result = ""
if select._limit:
result += "FIRST %s " % self.process(literal(select._limit))
if select._offset:
result += "SKIP %s " % self.process(literal(select._offset))
return result
def limit_clause(self, select):
return ""
dialect = default.DefaultDialect()
dialect.statement_compiler = MyCompiler
dialect.paramstyle = 'qmark'
dialect.positional = True
compiled = s2.compile(dialect=dialect)
assert \
[compiled.params[name] for name in compiled.positiontup] == [10, 5]
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon Apr 30, 2014
Michael Bayer (@zzzeek) wrote:
"SELECT FIRST n ROWS" using a bound parameter (only firebird has both),
combined with column-level subqueries
which also feature "limit" as well as "positional" bound parameters
(e.g. qmark style) would erroneously assign the subquery-level positions
before that of the enclosing SELECT, thus returning parameters which
are out of order. Fixes compilers that apply binds in select precolumns can be out of sync with column-nested subqueries #3038
→ 5da667e
sqlalchemy-bot commentedon Apr 30, 2014
Michael Bayer (@zzzeek) wrote:
"SELECT FIRST n ROWS" using a bound parameter (only firebird has both),
combined with column-level subqueries
which also feature "limit" as well as "positional" bound parameters
(e.g. qmark style) would erroneously assign the subquery-level positions
before that of the enclosing SELECT, thus returning parameters which
are out of order. Fixes compilers that apply binds in select precolumns can be out of sync with column-nested subqueries #3038
→ 2a45868
sqlalchemy-bot commentedon Apr 30, 2014
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Sep 27, 2017
Michael Bayer (@zzzeek) wrote:
"SELECT FIRST n ROWS" using a bound parameter (only firebird has both),
combined with column-level subqueries
which also feature "limit" as well as "positional" bound parameters
(e.g. qmark style) would erroneously assign the subquery-level positions
before that of the enclosing SELECT, thus returning parameters which
are out of order. Fixes compilers that apply binds in select precolumns can be out of sync with column-nested subqueries #3038
→ 5da667e