On Tue, Apr 24, 2018 at 4:43 PM, Steve Murphy <[email protected]> wrote:
> I'm just not getting it:
>
> Want:   select max(id) from table;
>
> attempt (latest):
>
> from sqlalchemy import *
> from sqlalchemy.engine import reflection
> from sqlalchemy import schema
> from sqlalchemy import exc
> from psycopg2 import *
> import re
> import time
> import os
> targethost = "192.168.181.204"
> targetdb = "postgresql://user:pword@"+ targethost +"/whatever"
> eng2 = create_engine(targetdb)
> con2 = eng2.connect()
> meta2 = MetaData()
> meta2.reflect(bind=eng2)
> insp2 = inspect(eng2)
> dst_tab = meta2.tables["tab1"]
> q3 = dst_tab.select([func.max(dst_tab.c.id)])
> maxphoneid = con2.execute(q3).scalar()
>
>
> I get: sqlalchemy.exc.ArgumentError: SQL expression object or string
> expected, got object of type <type 'list'> instead
>
> without the brackets in the select call, I get:
>
> sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) argument of
> WHERE must be type boolean, not type integer
> LINE 3: WHERE max(phone.id)
>
> There's gotta be a way! Any ideas?
>

You are calling the "select" method of a Table object. The first
parameter is expected to be the WHERE clause:

    
http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.Table.select

You probably just want to call the bare "select" function instead:

    q3 = select([func.max(dst_tab.c.id)])

    
http://docs.sqlalchemy.org/en/latest/core/selectable.html#sqlalchemy.sql.expression.select

Hope that helps,

Simon

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to