<h3 dir="auto">Describe the bug</h3>
<p dir="auto">I am unable to use big integer columns with <code class="notranslate">tuple_</code>  when querying the DB.</p>
<h3 dir="auto">To Reproduce</h3>
<p dir="auto">The following code is a minimal example:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="big_int = 2**31 + 123
session.add(Actor(id=big_int))
await session.commit()

s = select(Actor.id).where(tuple_(Actor.id, Actor.id) == tuple_(big_int, big_int))
await session.execute(s)"><pre class="notranslate"><span class="pl-s1">big_int</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span><span class="pl-c1">**</span><span class="pl-c1">31</span> <span class="pl-c1">+</span> <span class="pl-c1">123</span>
<span class="pl-s1">session</span>.<span class="pl-en">add</span>(<span class="pl-v">Actor</span>(<span class="pl-s1">id</span><span class="pl-c1">=</span><span class="pl-s1">big_int</span>))
<span class="pl-k">await</span> <span class="pl-s1">session</span>.<span class="pl-en">commit</span>()

<span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-en">select</span>(<span class="pl-v">Actor</span>.<span class="pl-s1">id</span>).<span class="pl-en">where</span>(<span class="pl-en">tuple_</span>(<span class="pl-v">Actor</span>.<span class="pl-s1">id</span>, <span class="pl-v">Actor</span>.<span class="pl-s1">id</span>) <span class="pl-c1">==</span> <span class="pl-en">tuple_</span>(<span class="pl-s1">big_int</span>, <span class="pl-s1">big_int</span>))
<span class="pl-k">await</span> <span class="pl-s1">session</span>.<span class="pl-en">execute</span>(<span class="pl-s1">s</span>)</pre></div>
<p dir="auto">Attempting to execute the query leads to the error below.</p>
<p dir="auto">I fixed the issue by using <code class="notranslate">func.cast(big_int, BigInteger)</code> explicitely before calling <code class="notranslate">tuple_</code>, but I would expect this to be automatic?</p>
<h3 dir="auto">Error</h3>
<p dir="auto"><code class="notranslate">sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) &lt;class 'asyncpg.exceptions.DataError'&gt;: invalid input for query argument $1: 2147483771 (value out of int32 range)</code></p>
<h3 dir="auto">Versions</h3>
<ul dir="auto">
<li>OS: Ubuntu 22.04</li>
<li>Python: 3.10.3</li>
<li>SQLAlchemy: 1.4.34</li>
<li>Database: Postgres</li>
<li>DBAPI (eg: psycopg, cx_oracle, mysqlclient): postgresql+asyncpg</li>
</ul>
<h3 dir="auto">Additional context</h3>
<p dir="auto">Full reproducible gist here:<br>
<a href="https://gist.github.com/Apakottur/62e38315949c0e57169cc95616299f22">https://gist.github.com/Apakottur/62e38315949c0e57169cc95616299f22</a></p>
<p dir="auto"><strong>Migrated issue, originally created by Henrique Alves (<a href="https://github.com/hcarvalhoalves">@hcarvalhoalves</a>)</strong></p>
<p dir="auto">I'm trying to do something that, in principle, should be simple: inject a expression-based column into an ORM-based Query. I've tried this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="query = db.session.query(MyClass).all()
# Using `now` just as an example, ideally it's something that takes a parameter
# so it can't be replaced by `orm.column_property`
some_expression = func.now() 
selectable = query.selectable
# The following works as expected, injecting the expression as a column
# the AnnotatedSelect object...
selectable.append_column(some_expression.label('some_column'))
# ... but I can't set it back on the query
query.selectable = selectable
query = query.order_by('some_column')
"><pre class="notranslate"><code class="notranslate">query = db.session.query(MyClass).all()
# Using `now` just as an example, ideally it's something that takes a parameter
# so it can't be replaced by `orm.column_property`
some_expression = func.now() 
selectable = query.selectable
# The following works as expected, injecting the expression as a column
# the AnnotatedSelect object...
selectable.append_column(some_expression.label('some_column'))
# ... but I can't set it back on the query
query.selectable = selectable
query = query.order_by('some_column')

</code></pre></div>
<p dir="auto">It fails with <code class="notranslate">AttributeError</code> since <code class="notranslate">query.selectable</code> is read-only. I haven't found another way to inject an expression by reading the docs or the source.</p>
<ul dir="auto">
<li>
<p dir="auto"><code class="notranslate">Query.add_column</code> isn't quite the same thing since you now get a <code class="notranslate">KeyedTuple</code> back, not a <code class="notranslate">MyClass</code> object with the injected attribute.</p>
</li>
<li>
<p dir="auto"><code class="notranslate">orm.column_property</code> is of limited usefulness since you can't pass arguments only known at runtime instead of class-evaluation time.</p>
</li>
</ul>
<p dir="auto">I thought SQLAlchemy made things like this a breeze, but I've spent days without finding an adequate solution. Either I'm missing something, or an API for this is badly needed.</p>