sort table by primary keys

10 views
Skip to first unread message

sumau

unread,
Jan 5, 2020, 7:02:01 PM1/5/20
to sqlalchemy
Hello

I was wondering if it was possible to sort a table by its 'unspecified' primary keys using the SQL Alchemy Expression Language?

I have tried the following:

t = Table ('test',metadata,autoload=True)
select([t]).order_by(t.primary_key.columns)

but I get the following error:

sqlalchemy.exc.ArgumentError: SQL expression object expected, got object of type <class 'sqlalchemy.sql.base.ColumnCollection'> instead

nRegards
Soumaya

Mike Bayer

unread,
Jan 5, 2020, 9:20:01 PM1/5/20
to noreply-spamdigest via sqlalchemy
did you try:

order_by(*t.primary_key)

?
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
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 sqlalchemy+...@googlegroups.com.

sumau

unread,
Jan 6, 2020, 4:35:07 PM1/6/20
to sqlalchemy
Head-smack!

Thanks and happy new year

Soumaya


On Monday, 6 January 2020 02:20:01 UTC, Mike Bayer wrote:
did you try:

order_by(*t.primary_key)

?



On Sun, Jan 5, 2020, at 7:02 PM, sumau wrote:
Hello

I was wondering if it was possible to sort a table by its 'unspecified' primary keys using the SQL Alchemy Expression Language?

I have tried the following:

t = Table ('test',metadata,autoload=True)
select([t]).order_by(t.primary_key.columns)

but I get the following error:

sqlalchemy.exc.ArgumentError: SQL expression object expected, got object of type <class 'sqlalchemy.sql.base.ColumnCollection'> instead

nRegards
Soumaya


--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
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 sqlal...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages