Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-20 Thread Mike Bayer
I hope you can forgive that I've been allowing you to figure this out
on your own as the emails here seem to be more of glimpses of an
in-progress situation rather than something those of us who are
outside of your project can easily engage within, if you are stuck on
something is there any chance you can provide a very succinct and
minimal Python script that illustrates the specific issue all at once
in a runnable format?   I see you are using things like LATERAL which
are very sophisticated Postgresql features.

On Mon, May 20, 2019 at 9:28 AM Scheck David  wrote:
>
> Ok I just identified the issue. It seems that there is a conflict between 2 
> subqueries :
>
> in my model.I have this :
> statussen = relationship(
> "PersoonStatus",
> order_by="desc(PersoonStatus.status_datum)",
> backref='persoon',
> cascade='all, delete, delete-orphan',
> lazy='subquery'
> )
>
> and if I do this query :
>
> last_statuses = aliased(
> statussen_table_name,
> self.session.query(
> getattr(statussen_table_name, issue_id_field),
>  statussen_table_name.status_id)\
> .join(Status).order_by(Status.datum.desc())\
> .limit(1).subquery().lateral())
>
> there is a conflict between this 2 subqueries who target the same table.
>
> Is there a workaround to prevent this conflict?
>
> any idea?
>
> --
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/61df1e98-8475-4d3a-a21b-20aff412d4fa%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CA%2BRjkXEgT9Zg8xkFexO7kthBrWzxtYW74xnOifk-3b9CMgsFQg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-20 Thread Scheck David
Ok I just identified the issue. It seems that there is a conflict between 2 
subqueries :

in my model.I have this : 
statussen = relationship(
"PersoonStatus",
order_by="desc(PersoonStatus.status_datum)",
backref='persoon',
cascade='all, delete, delete-orphan',
lazy='subquery'
)

and if I do this query : 

last_statuses = aliased(
statussen_table_name,
self.session.query(
getattr(statussen_table_name, 
issue_id_field),
 statussen_table_name.status_id)\
.join(Status).order_by(Status.datum.desc())\
.limit(1).subquery().lateral())

there is a conflict between this 2 subqueries who target the same table.

Is there a workaround to prevent this conflict?

any idea?

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/61df1e98-8475-4d3a-a21b-20aff412d4fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-17 Thread Scheck David
I really don't know why this query returns me this .. totally mysterious

Le jeudi 16 mai 2019 16:27:50 UTC+2, Scheck David a écrit :
>
> I finished by a query like that : 
>
>
> last_statuses = aliased(statussen_table_name, 
> self.session.query(getattr(statussen_table_name, object_name),
> 
> statussen_table_name.status_id).join(Status).order_by(Status.datum.desc()).limit(1).subquery().lateral())
> return 
> self.session.query(self.cls).join(last_statuses).filter(Status.statustype_id 
> > 50).all()
>
> the problem is that there is a problem in the query : 
>
> sqlalchemy.exc.InvalidRequestError: Select statement 'SELECT 
> statussen.datum 
>
> FROM (SELECT personen.id AS personen_id 
>
> FROM statussen, personen JOIN LATERAL (SELECT 
> personen_statussen.persoon_id AS persoon_id, personen_statussen.status_id 
> AS status_id 
>
> FROM personen_statussen JOIN statussen ON statussen.id = 
> personen_statussen.status_id ORDER BY statussen.datum DESC
>
>  LIMIT :param_1) AS anon_2 ON personen.id = anon_2.persoon_id 
>
> WHERE statussen.statustype_id > :statustype_id_1) AS anon_1, 
> personen_statussen 
>
> WHERE statussen.id = personen_statussen.status_id' returned no FROM 
> clauses due to auto-correlation; specify correlate() to control 
> correlation manually.
>

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/94817a4b-3579-44de-ab48-1251baf21ac1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-16 Thread Scheck David
I finished by a query like that : 


last_statuses = aliased(statussen_table_name, 
self.session.query(getattr(statussen_table_name, object_name),

statussen_table_name.status_id).join(Status).order_by(Status.datum.desc()).limit(1).subquery().lateral())
return 
self.session.query(self.cls).join(last_statuses).filter(Status.statustype_id 
> 50).all()

the problem is that there is a problem in the query : 

sqlalchemy.exc.InvalidRequestError: Select statement 'SELECT 
statussen.datum 

FROM (SELECT personen.id AS personen_id 

FROM statussen, personen JOIN LATERAL (SELECT personen_statussen.persoon_id 
AS persoon_id, personen_statussen.status_id AS status_id 

FROM personen_statussen JOIN statussen ON statussen.id = 
personen_statussen.status_id ORDER BY statussen.datum DESC

 LIMIT :param_1) AS anon_2 ON personen.id = anon_2.persoon_id 

WHERE statussen.statustype_id > :statustype_id_1) AS anon_1, 
personen_statussen 

WHERE statussen.id = personen_statussen.status_id' returned no FROM clauses 
due to auto-correlation; specify correlate() to control correlation 
manually.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/930ee74c-1892-4621-8006-51cbd94e020e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-16 Thread Scheck David
I finished by a query like that : 


last_statuses = aliased(statussen_table_name, 
self.session.query(getattr(statussen_table_name, object_name),

statussen_table_name.status_id).join(Status).order_by(Status.datum.desc()).limit(1).subquery().lateral())
return 
self.session.query(self.cls).join(last_statuses).filter(Status.statustype_id 
> 50).all()

the problem is that there is a problem in the query : 

sqlalchemy.exc.InvalidRequestError: Select statement 'SELECT 
statussen.datum 

FROM (SELECT personen.id AS personen_id 

FROM statussen, personen JOIN LATERAL (SELECT personen_statussen.persoon_id 
AS persoon_id, personen_statussen.status_id AS status_id 

FROM personen_statussen JOIN statussen ON statussen.id = 
personen_statussen.status_id ORDER BY statussen.datum DESC

 LIMIT :param_1) AS anon_2 ON personen.id = anon_2.persoon_id 

WHERE statussen.statustype_id > :statustype_id_1) AS anon_1, 
personen_statussen 

WHERE statussen.id = personen_statussen.status_id' returned no FROM clauses 
due to auto-correlation; specify correlate() to control correlation 
manually.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/f7fef252-8fc6-4cb5-a8e4-1270cfacab21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-15 Thread Scheck David
For a full state of what I have 

https://dpaste.de/vV8k

the goal is to convert the sql query to SQLAlchemy.

Thanks in advance for any help

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/d17f598c-11fc-4921-b165-7f92d95b385c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-14 Thread Scheck David
In fact this I will use as a method on a datamanager use for different
objects. In this sql the object is erfgoedobjecten but it will change.

Le mar. 14 mai 2019 à 18:06, Jonathan Vanasco  a
écrit :

>
>
> On Tuesday, May 14, 2019 at 10:29:58 AM UTC-4, Scheck David wrote:
>>
>> I'm near the result of sql:
>>
>> https://dpaste.de/1XYa#
>>
>>>

> Do you want this to be an attribute/relationship on the class or to run
> this as a separate query?
>
> --
> 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 a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sqlalchemy/Cju-PF7mV58/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/36b8df42-960c-4f75-adee-a4a59cc87636%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 

With kindest regards,


*David SCHECK*

PRESIDENT/DEVELOPER

[image: Signature Logo Sphax Bleu-01.png]

Phone: +32 4 87 86 70 12
Visit our website ! https://www.sphax.org

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAOPG6sc%3DgxYFbRHF46kqnRRyhx0-%2BJiC4L06S5hDQNc28a19GA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-14 Thread Jonathan Vanasco


On Tuesday, May 14, 2019 at 10:29:58 AM UTC-4, Scheck David wrote:
>
> I'm near the result of sql:
>
> https://dpaste.de/1XYa#
>
>>
>>>
Do you want this to be an attribute/relationship on the class or to run 
this as a separate query? 

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/36b8df42-960c-4f75-adee-a4a59cc87636%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-14 Thread Scheck David
I'm near the result of sql:

https://dpaste.de/1XYa#

Le lundi 13 mai 2019 17:46:29 UTC+2, Mike Bayer a écrit :
>
>
>
> On Mon, May 13, 2019 at 10:37 AM Scheck David  > wrote:
>
>> the problem is that I can't use SQL for this because this is a mixins 
>> that I use for several objects (tables) because they all have this status 
>> structure... yes it's quite difficult to do :
>>
>
> I don't know what it is you want to do so if you could illustrate the SQL 
> that resembles what you want, I'd have some idea.   If you are trying to 
> build a Query object, then you are working with SQL and you'd need to 
> understand the structure you're looking for.
>
>
>  
>
>>
>> right now I'm on this stage, but still don't work
>> self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
>> .group_by(Object).with_entities(Object, 
>> func.max(Status.datum).label("status_datum")).subquery()
>>
>> self.session.query(Object).join((sub, sub.c.id == Status.id))\
>> .filter(sub.c.statustype_id > 50)
>>
>> Le lun. 13 mai 2019 à 16:26, Mike Bayer > > a écrit :
>>
>>> Hi -
>>>
>>> I was hoping someone could jump in on this.
>>>
>>> do you know the SQL that you want to emit?  E.g. plain SQL string.   I
>>> can help you do that part.
>>>
>>>
>>> On Mon, May 13, 2019 at 9:11 AM Scheck David >> > wrote:
>>> >
>>> > I think I'm near but I can't finish :
>>> >
>>> > for all the structure : https://dpaste.de/fek5#L
>>> >
>>> > and here my query :
>>> >
>>> > self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
>>> > .group_by(Object).with_entities(Object, 
>>> func.max(Status.datum).label("status_datum")).subquery()
>>> >
>>> > self.session.query(Object).join((sub, sub.c.id == Status.id))\
>>> > .filter(sub.c.statustype_id > 50)
>>> >
>>> > but status type not reachable.
>>> >
>>> >
>>> > --
>>> > 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 sqlal...@googlegroups.com .
>>> > To post to this group, send email to sqlal...@googlegroups.com 
>>> .
>>> > Visit this group at https://groups.google.com/group/sqlalchemy.
>>> > To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/sqlalchemy/fe2da543-2710-4b44-9f88-e68c5e35faea%40googlegroups.com
>>> .
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>> -- 
>>> 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 a topic in the 
>>> Google Groups "sqlalchemy" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/sqlalchemy/Cju-PF7mV58/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> sqlal...@googlegroups.com .
>>> To post to this group, send email to sqlal...@googlegroups.com 
>>> .
>>> Visit this group at https://groups.google.com/group/sqlalchemy.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/sqlalchemy/CA%2BRjkXF3d_pffLqFLYpSNw80E%3D_2ULhh0pTiqBG-F1dFjA9r1Q%40mail.gmail.com
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> -- 
>>
>> With kindest regards,
>>
>>
>> *David SCHECK*
>>
>> PRESIDENT/DEVELOPER
>>
>> [image: Signature Logo Sphax Bleu-01.png]
>>
>> Phone: +32 4 87 86 70 12
>> Visit our website ! https://www.sphax.org
>>
>> -- 
>> 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 sqlal...@googlegroups.com .
>> To post to this group, send email to sqlal...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sqlalchemy/CAOPG6scR1rWJTBN%3DEArX2buPqiVsGaPiQq4wYGU58Renqae0kA%40mail.gmail.com
>>  
>> 
>> .
>> For more options, 

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-14 Thread Scheck David
Here is the last version of my sql query:

https://dpaste.de/8UhP

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/23195ece-7551-483a-bd85-61a00a8b8748%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-14 Thread Scheck David

>
>
> Here is the sql generated for this query : https://dpaste.de/bJsc
 

Le lundi 13 mai 2019 17:46:29 UTC+2, Mike Bayer a écrit :
>
>
>
> On Mon, May 13, 2019 at 10:37 AM Scheck David  > wrote:
>
>> the problem is that I can't use SQL for this because this is a mixins 
>> that I use for several objects (tables) because they all have this status 
>> structure... yes it's quite difficult to do :
>>
>
> I don't know what it is you want to do so if you could illustrate the SQL 
> that resembles what you want, I'd have some idea.   If you are trying to 
> build a Query object, then you are working with SQL and you'd need to 
> understand the structure you're looking for.
>
>
>  
>
>>
>> right now I'm on this stage, but still don't work
>> self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
>> .group_by(Object).with_entities(Object, 
>> func.max(Status.datum).label("status_datum")).subquery()
>>
>> self.session.query(Object).join((sub, sub.c.id == Status.id))\
>> .filter(sub.c.statustype_id > 50)
>>
>> Le lun. 13 mai 2019 à 16:26, Mike Bayer > > a écrit :
>>
>>> Hi -
>>>
>>> I was hoping someone could jump in on this.
>>>
>>> do you know the SQL that you want to emit?  E.g. plain SQL string.   I
>>> can help you do that part.
>>>
>>>
>>> On Mon, May 13, 2019 at 9:11 AM Scheck David >> > wrote:
>>> >
>>> > I think I'm near but I can't finish :
>>> >
>>> > for all the structure : https://dpaste.de/fek5#L
>>> >
>>> > and here my query :
>>> >
>>> > self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
>>> > .group_by(Object).with_entities(Object, 
>>> func.max(Status.datum).label("status_datum")).subquery()
>>> >
>>> > self.session.query(Object).join((sub, sub.c.id == Status.id))\
>>> > .filter(sub.c.statustype_id > 50)
>>> >
>>> > but status type not reachable.
>>> >
>>> >
>>> > --
>>> > 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 sqlal...@googlegroups.com .
>>> > To post to this group, send email to sqlal...@googlegroups.com 
>>> .
>>> > Visit this group at https://groups.google.com/group/sqlalchemy.
>>> > To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/sqlalchemy/fe2da543-2710-4b44-9f88-e68c5e35faea%40googlegroups.com
>>> .
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>> -- 
>>> 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 a topic in the 
>>> Google Groups "sqlalchemy" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/sqlalchemy/Cju-PF7mV58/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> sqlal...@googlegroups.com .
>>> To post to this group, send email to sqlal...@googlegroups.com 
>>> .
>>> Visit this group at https://groups.google.com/group/sqlalchemy.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/sqlalchemy/CA%2BRjkXF3d_pffLqFLYpSNw80E%3D_2ULhh0pTiqBG-F1dFjA9r1Q%40mail.gmail.com
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> -- 
>>
>> With kindest regards,
>>
>>
>> *David SCHECK*
>>
>> PRESIDENT/DEVELOPER
>>
>> [image: Signature Logo Sphax Bleu-01.png]
>>
>> Phone: +32 4 87 86 70 12
>> Visit our website ! https://www.sphax.org
>>
>> -- 
>> 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 sqlal...@googlegroups.com .
>> To post to this group, send email to sqlal...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sqlalchemy/CAOPG6scR1rWJTBN%3DEArX2buPqiVsGaPiQq4wYGU58Renqae0kA%40mail.gmail.com
>>  
>> 
>> .
>> 

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-14 Thread Scheck David

>
> Here is my sql for this case 
>

SELECT DISTINCT erfgoed.id as id,
statussen.statustype_id as statype_id,
statussen.datum as datum,
erfgoed.naam as naam
FROM erfgoedobjecten as erfgoed
JOIN erfgoedobjecten_statussen as erfgoedobjectstatus
ON erfgoed.id = erfgoedobjectstatus.erfgoedobject_id
JOIN statussen
ON statussen.id = 
(
SELECT id
FROM statussen
WHERE statussen.id = erfgoedobjectstatus.status_id
ORDER BY datum DESC
)
WHERE statussen.statustype_id > 50


-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/4b07dd75-df93-4896-91ff-95edcdd74453%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-14 Thread Scheck David
Ok, I'll try to build this query in sql. thanks :)

Le lun. 13 mai 2019 à 17:43, James Fennell  a
écrit :

> I think Mike's suggestion was to construct the raw SQL string you want,
> then reverse engineer to get the correct SQL Alchemy code, which you can
> then use with your different models. For complicated SQL logic I think this
> is a good practice in general.
>
> You current question seems like a general SQL question rather than
> something specific to SQL Alchemy. After you've the SQL, we could discuss
> the reverse engineering.
>
> On Mon, May 13, 2019, 10:37 AM Scheck David 
>> the problem is that I can't use SQL for this because this is a mixins
>> that I use for several objects (tables) because they all have this status
>> structure... yes it's quite difficult to do :
>>
>> right now I'm on this stage, but still don't work
>> self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
>> .group_by(Object).with_entities(Object,
>> func.max(Status.datum).label("status_datum")).subquery()
>>
>> self.session.query(Object).join((sub, sub.c.id == Status.id))\
>> .filter(sub.c.statustype_id > 50)
>>
>> Le lun. 13 mai 2019 à 16:26, Mike Bayer  a
>> écrit :
>>
>>> Hi -
>>>
>>> I was hoping someone could jump in on this.
>>>
>>> do you know the SQL that you want to emit?  E.g. plain SQL string.   I
>>> can help you do that part.
>>>
>>>
>>> On Mon, May 13, 2019 at 9:11 AM Scheck David  wrote:
>>> >
>>> > I think I'm near but I can't finish :
>>> >
>>> > for all the structure : https://dpaste.de/fek5#L
>>> >
>>> > and here my query :
>>> >
>>> > self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
>>> > .group_by(Object).with_entities(Object,
>>> func.max(Status.datum).label("status_datum")).subquery()
>>> >
>>> > self.session.query(Object).join((sub, sub.c.id == Status.id))\
>>> > .filter(sub.c.statustype_id > 50)
>>> >
>>> > but status type not reachable.
>>> >
>>> >
>>> > --
>>> > 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 sqlalchemy+unsubscr...@googlegroups.com.
>>> > To post to this group, send email to sqlalchemy@googlegroups.com.
>>> > Visit this group at https://groups.google.com/group/sqlalchemy.
>>> > To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/sqlalchemy/fe2da543-2710-4b44-9f88-e68c5e35faea%40googlegroups.com
>>> .
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> 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 a topic in the
>>> Google Groups "sqlalchemy" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/sqlalchemy/Cju-PF7mV58/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> sqlalchemy+unsubscr...@googlegroups.com.
>>> To post to this group, send email to sqlalchemy@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/sqlalchemy.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/sqlalchemy/CA%2BRjkXF3d_pffLqFLYpSNw80E%3D_2ULhh0pTiqBG-F1dFjA9r1Q%40mail.gmail.com
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>>
>> With kindest regards,
>>
>>
>> *David SCHECK*
>>
>> PRESIDENT/DEVELOPER
>>
>> [image: Signature Logo Sphax Bleu-01.png]
>>
>> Phone: +32 4 87 86 70 12
>> Visit our website ! https://www.sphax.org
>>
>> --
>> 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 sqlalchemy+unsubscr...@googlegroups.com.
>> To post to this group, send email to sqlalchemy@googlegroups.com.
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sqlalchemy/CAOPG6scR1rWJTBN%3DEArX2buPqiVsGaPiQq4wYGU58Renqae0kA%40mail.gmail.com
>> 

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Mike Bayer
On Mon, May 13, 2019 at 10:37 AM Scheck David  wrote:

> the problem is that I can't use SQL for this because this is a mixins that
> I use for several objects (tables) because they all have this status
> structure... yes it's quite difficult to do :
>

I don't know what it is you want to do so if you could illustrate the SQL
that resembles what you want, I'd have some idea.   If you are trying to
build a Query object, then you are working with SQL and you'd need to
understand the structure you're looking for.




>
> right now I'm on this stage, but still don't work
> self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
> .group_by(Object).with_entities(Object,
> func.max(Status.datum).label("status_datum")).subquery()
>
> self.session.query(Object).join((sub, sub.c.id == Status.id))\
> .filter(sub.c.statustype_id > 50)
>
> Le lun. 13 mai 2019 à 16:26, Mike Bayer  a
> écrit :
>
>> Hi -
>>
>> I was hoping someone could jump in on this.
>>
>> do you know the SQL that you want to emit?  E.g. plain SQL string.   I
>> can help you do that part.
>>
>>
>> On Mon, May 13, 2019 at 9:11 AM Scheck David  wrote:
>> >
>> > I think I'm near but I can't finish :
>> >
>> > for all the structure : https://dpaste.de/fek5#L
>> >
>> > and here my query :
>> >
>> > self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
>> > .group_by(Object).with_entities(Object,
>> func.max(Status.datum).label("status_datum")).subquery()
>> >
>> > self.session.query(Object).join((sub, sub.c.id == Status.id))\
>> > .filter(sub.c.statustype_id > 50)
>> >
>> > but status type not reachable.
>> >
>> >
>> > --
>> > 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 sqlalchemy+unsubscr...@googlegroups.com.
>> > To post to this group, send email to sqlalchemy@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/sqlalchemy.
>> > To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sqlalchemy/fe2da543-2710-4b44-9f88-e68c5e35faea%40googlegroups.com
>> .
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> 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 a topic in the
>> Google Groups "sqlalchemy" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/sqlalchemy/Cju-PF7mV58/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> sqlalchemy+unsubscr...@googlegroups.com.
>> To post to this group, send email to sqlalchemy@googlegroups.com.
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sqlalchemy/CA%2BRjkXF3d_pffLqFLYpSNw80E%3D_2ULhh0pTiqBG-F1dFjA9r1Q%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
>
> With kindest regards,
>
>
> *David SCHECK*
>
> PRESIDENT/DEVELOPER
>
> [image: Signature Logo Sphax Bleu-01.png]
>
> Phone: +32 4 87 86 70 12
> Visit our website ! https://www.sphax.org
>
> --
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/CAOPG6scR1rWJTBN%3DEArX2buPqiVsGaPiQq4wYGU58Renqae0kA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread James Fennell
I think Mike's suggestion was to construct the raw SQL string you want,
then reverse engineer to get the correct SQL Alchemy code, which you can
then use with your different models. For complicated SQL logic I think this
is a good practice in general.

You current question seems like a general SQL question rather than
something specific to SQL Alchemy. After you've the SQL, we could discuss
the reverse engineering.

On Mon, May 13, 2019, 10:37 AM Scheck David  the problem is that I can't use SQL for this because this is a mixins that
> I use for several objects (tables) because they all have this status
> structure... yes it's quite difficult to do :
>
> right now I'm on this stage, but still don't work
> self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
> .group_by(Object).with_entities(Object,
> func.max(Status.datum).label("status_datum")).subquery()
>
> self.session.query(Object).join((sub, sub.c.id == Status.id))\
> .filter(sub.c.statustype_id > 50)
>
> Le lun. 13 mai 2019 à 16:26, Mike Bayer  a
> écrit :
>
>> Hi -
>>
>> I was hoping someone could jump in on this.
>>
>> do you know the SQL that you want to emit?  E.g. plain SQL string.   I
>> can help you do that part.
>>
>>
>> On Mon, May 13, 2019 at 9:11 AM Scheck David  wrote:
>> >
>> > I think I'm near but I can't finish :
>> >
>> > for all the structure : https://dpaste.de/fek5#L
>> >
>> > and here my query :
>> >
>> > self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
>> > .group_by(Object).with_entities(Object,
>> func.max(Status.datum).label("status_datum")).subquery()
>> >
>> > self.session.query(Object).join((sub, sub.c.id == Status.id))\
>> > .filter(sub.c.statustype_id > 50)
>> >
>> > but status type not reachable.
>> >
>> >
>> > --
>> > 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 sqlalchemy+unsubscr...@googlegroups.com.
>> > To post to this group, send email to sqlalchemy@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/sqlalchemy.
>> > To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sqlalchemy/fe2da543-2710-4b44-9f88-e68c5e35faea%40googlegroups.com
>> .
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> 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 a topic in the
>> Google Groups "sqlalchemy" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/sqlalchemy/Cju-PF7mV58/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> sqlalchemy+unsubscr...@googlegroups.com.
>> To post to this group, send email to sqlalchemy@googlegroups.com.
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sqlalchemy/CA%2BRjkXF3d_pffLqFLYpSNw80E%3D_2ULhh0pTiqBG-F1dFjA9r1Q%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
>
> With kindest regards,
>
>
> *David SCHECK*
>
> PRESIDENT/DEVELOPER
>
> [image: Signature Logo Sphax Bleu-01.png]
>
> Phone: +32 4 87 86 70 12
> Visit our website ! https://www.sphax.org
>
> --
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/CAOPG6scR1rWJTBN%3DEArX2buPqiVsGaPiQq4wYGU58Renqae0kA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Scheck David
the problem is that I can't use SQL for this because this is a mixins that
I use for several objects (tables) because they all have this status
structure... yes it's quite difficult to do :

right now I'm on this stage, but still don't work
self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
.group_by(Object).with_entities(Object,
func.max(Status.datum).label("status_datum")).subquery()

self.session.query(Object).join((sub, sub.c.id == Status.id))\
.filter(sub.c.statustype_id > 50)

Le lun. 13 mai 2019 à 16:26, Mike Bayer  a écrit :

> Hi -
>
> I was hoping someone could jump in on this.
>
> do you know the SQL that you want to emit?  E.g. plain SQL string.   I
> can help you do that part.
>
>
> On Mon, May 13, 2019 at 9:11 AM Scheck David  wrote:
> >
> > I think I'm near but I can't finish :
> >
> > for all the structure : https://dpaste.de/fek5#L
> >
> > and here my query :
> >
> > self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
> > .group_by(Object).with_entities(Object,
> func.max(Status.datum).label("status_datum")).subquery()
> >
> > self.session.query(Object).join((sub, sub.c.id == Status.id))\
> > .filter(sub.c.statustype_id > 50)
> >
> > but status type not reachable.
> >
> >
> > --
> > 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 sqlalchemy+unsubscr...@googlegroups.com.
> > To post to this group, send email to sqlalchemy@googlegroups.com.
> > Visit this group at https://groups.google.com/group/sqlalchemy.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/fe2da543-2710-4b44-9f88-e68c5e35faea%40googlegroups.com
> .
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sqlalchemy/Cju-PF7mV58/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/CA%2BRjkXF3d_pffLqFLYpSNw80E%3D_2ULhh0pTiqBG-F1dFjA9r1Q%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 

With kindest regards,


*David SCHECK*

PRESIDENT/DEVELOPER

[image: Signature Logo Sphax Bleu-01.png]

Phone: +32 4 87 86 70 12
Visit our website ! https://www.sphax.org

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAOPG6scR1rWJTBN%3DEArX2buPqiVsGaPiQq4wYGU58Renqae0kA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Mike Bayer
Hi -

I was hoping someone could jump in on this.

do you know the SQL that you want to emit?  E.g. plain SQL string.   I
can help you do that part.


On Mon, May 13, 2019 at 9:11 AM Scheck David  wrote:
>
> I think I'm near but I can't finish :
>
> for all the structure : https://dpaste.de/fek5#L
>
> and here my query :
>
> self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
> .group_by(Object).with_entities(Object, 
> func.max(Status.datum).label("status_datum")).subquery()
>
> self.session.query(Object).join((sub, sub.c.id == Status.id))\
> .filter(sub.c.statustype_id > 50)
>
> but status type not reachable.
>
>
> --
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/fe2da543-2710-4b44-9f88-e68c5e35faea%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CA%2BRjkXF3d_pffLqFLYpSNw80E%3D_2ULhh0pTiqBG-F1dFjA9r1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Scheck David
I think I'm near but I can't finish : 

for all the structure : https://dpaste.de/fek5#L

and here my query : 

self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\
.group_by(Object).with_entities(Object, 
func.max(Status.datum).label("status_datum")).subquery()

self.session.query(Object).join((sub, sub.c.id == Status.id))\
.filter(sub.c.statustype_id > 50)

but status type not reachable.


-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/fe2da543-2710-4b44-9f88-e68c5e35faea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: Query last relation created and attributes

2019-05-10 Thread Scheck David
I did this :


   1. self.session.query(Object)\
   2. .join(Object.statussen)\
   3. .filter(Status.id == self.session.query(Status).order_by(desc(Status.
   datum)).first().id)\
   4. .filter(Statustype.id > 50).all()


but I still don"t get it

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/99179cb4-a6b0-409f-a4b1-06fc5abf7fb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.