[sqlalchemy] Problems with sqlalchemy and timestamps

2017-03-06 Thread karl . lattimer
Hi, I'm having some trouble with sqlalchemy and timestamps 

I have a schema which looks like this 


class MyTable(Entity):
__tablename__ = "MyTable"
id = Column(Integer, primary_key=True)
tstamp = Column(DateTime, nullable=False)


when I run a query such as 


current_time = datetime.datetime.utcnow()
s = current_time - datetime.timedelta(hours=1)
hour_ago = s.isoformat()
query = session.query(func.count(MyTable)).filter(MyTable > hour_ago)

I will get the following StatementError - but not on my local testing (mac 
os sierra) system, only when testing the system on our live docker based 
system (Ubuntu:wily) 

Has anyone come across this issue before? I've tried using a date time 
object but that resulted to the same problem so I opted to change to the 
iso string. It seems that the timestamp is simply not being passed to the 
query statement in the parameters.

StatementError: (sqlalchemy.exc.InvalidRequestError) Can't reconnect until 
invalid transaction is rolled back [SQL: u'SELECT count(`MyTable`.id) AS 
count_1 \nFROM `MyTable` \nWHERE `MyTable`.tstamp > %s'] [parameters: [
{}
]]

Any help would be much appreciated.

Regards,
 K,

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Problems with sqlalchemy and timestamps

2017-03-06 Thread mike bayer
a ROLLBACK is occurring which suggests a different error has occurred 
and is being swallowed - the transaction can then not continue. Does 
your production environment have logs which would illustrate other 
exceptions and reasons for rollbacks prior to this one?   It is possible 
that something like autoflush on query is causing a flush to fail, 
something lime that.






On 03/06/2017 08:03 AM, karl.latti...@innolabs.uk wrote:

Hi, I'm having some trouble with sqlalchemy and timestamps

I have a schema which looks like this


class MyTable(Entity):
__tablename__ = "MyTable"
id = Column(Integer, primary_key=True)
tstamp = Column(DateTime, nullable=False)


when I run a query such as


current_time = datetime.datetime.utcnow()
s = current_time - datetime.timedelta(hours=1)
hour_ago = s.isoformat()
query = session.query(func.count(MyTable)).filter(MyTable > hour_ago)

I will get the following StatementError - but not on my local testing
(mac os sierra) system, only when testing the system on our live docker
based system (Ubuntu:wily)

Has anyone come across this issue before? I've tried using a date time
object but that resulted to the same problem so I opted to change to the
iso string. It seems that the timestamp is simply not being passed to
the query statement in the parameters.

StatementError: (sqlalchemy.exc.InvalidRequestError) Can't reconnect
until invalid transaction is rolled back [SQL: u'SELECT
count(`MyTable`.id) AS count_1 \nFROM `MyTable` \nWHERE `MyTable`.tstamp

%s'] [parameters: [

{}
]]

Any help would be much appreciated.

Regards,
 K,

--
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.
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.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Problems with sqlalchemy and timestamps

2017-03-06 Thread Jonathan Vanasco


On Monday, March 6, 2017 at 10:21:37 AM UTC-5, Mike Bayer wrote:
>
> a ROLLBACK is occurring which suggests a different error has occurred 
> and is being swallowed - the transaction can then not continue. Does 
> your production environment have logs which would illustrate other 
> exceptions and reasons for rollbacks prior to this one?   It is possible 
> that something like autoflush on query is causing a flush to fail, 
> something lime that. 
>

Can you also share your connection strings for each environment?  You 
should also enable logging on sqlalchemy and the backend server. 

In my experience with situations like this, a certain approach/command/etc 
works on one database but not another -- and that triggers the error.  When 
you look at logs and the connection string , it becomes easy to pinpoint.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Select the hybrid method result on the query

2017-03-06 Thread mike bayer



On 03/06/2017 04:16 PM, Leonardo Mata wrote:

Hello, My applications does some ordering using the distance from
latitude and longitude haversine distance, i was able to calculate this
using @hybrid.method and @.*expression, but i can't output the
calculated distance:

/class PartnerAddress(db.Model, WithTimestampsModel, SerializeMixin):/
//
/# Columns/
/id = db.Column(db.Integer(), primary_key=True, nullable=False)/
/
/
/partner_id = db.Column(/
/db.Integer(),/
/db.ForeignKey('partner.id'),/
/nullable=False/
/)/
/
/
/latitude = db.Column(db.Numeric(precision=9, scale=7), nullable=False)/
/longitude = db.Column(db.Numeric(precision=10, scale=7),
nullable=False)/
/   /
/
/
/@hybrid_method/
/def distance(self, lat, lng):/
//
/return math.acos(math.cos(math.radians(self.latitude)) *
math.cos(math.radians(lat)) */
/   math.cos(math.radians(self.longitude) -
math.radians(lng)) +/
/   math.sin(math.radians(self.latitude)) *
math.sin(math.radians(lat))) * 6371/
/
/
/@distance.expression/
/def distance(cls, lat, lng):/
/return func.acos(func.cos(func.radians(cls.latitude)) *
func.cos(func.radians(lat)) */
/ func.cos(func.radians(lng) -
func.radians(cls.longitude)) +/
/ func.sin(func.radians(cls.latitude)) *
func.sin(func.radians(lat))) * 6371/
/
/
/
/
/class PartnerV3(db.Model, WithTimestampsModel,/
/SoftDeletableModel, SerializeMixin):/
//
/
/
/name = db.Column(db.String(128), nullable=False)/
//
/
/
/address = db.relationship(/
/'mustafar.partner.v3.models.address.PartnerAddress',/
/backref='partner',/
/uselist=False/
/)/


when querying like this:

query =
PartnerV3.query.join(PartnerAddress).order_by(PartnerAddress.distance(lat,
lng)).paginate(1,10, False)

I can paginate the result, but it returns only the PartnerV3 object, i
can't access the distance.

How do I access this distance property?


you have a PartnerV3 there so the PartnerAddress is on the .address 
property:


query = 
PartnerV3.query.join(PartnerAddress).order_by(PartnerAddress.distance(lat, 
lng))



some_partner = query.first()

partner_address = some_partner.address
distance = partner_address.distance(lat, lng)











--
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.
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.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Select the hybrid method result on the query

2017-03-06 Thread Leonardo Mata
Hello, My applications does some ordering using the distance from latitude 
and longitude haversine distance, i was able to calculate this using 
@hybrid.method and @.*expression, but i can't output the calculated 
distance:

*class PartnerAddress(db.Model, WithTimestampsModel, SerializeMixin):*

*# Columns*
*id = db.Column(db.Integer(), primary_key=True, nullable=False)*

*partner_id = db.Column(*
*db.Integer(),*
*db.ForeignKey('partner.id'),*
*nullable=False*
*)*

*latitude = db.Column(db.Numeric(precision=9, scale=7), nullable=False)*
*longitude = db.Column(db.Numeric(precision=10, scale=7), 
nullable=False)*
   

*@hybrid_method*
*def distance(self, lat, lng):*

*return math.acos(math.cos(math.radians(self.latitude)) * 
math.cos(math.radians(lat)) **
*   math.cos(math.radians(self.longitude) - math.radians(lng)) 
+*
*   math.sin(math.radians(self.latitude)) * 
math.sin(math.radians(lat))) * 6371*

*@distance.expression*
*def distance(cls, lat, lng):*
*return func.acos(func.cos(func.radians(cls.latitude)) * 
func.cos(func.radians(lat)) **
* func.cos(func.radians(lng) - 
func.radians(cls.longitude)) +*
* func.sin(func.radians(cls.latitude)) * 
func.sin(func.radians(lat))) * 6371*


*class PartnerV3(db.Model, WithTimestampsModel,*
*SoftDeletableModel, SerializeMixin):*


*name = db.Column(db.String(128), nullable=False)*


*address = db.relationship(*
*'mustafar.partner.v3.models.address.PartnerAddress',*
*backref='partner',*
*uselist=False*
*)*


when querying like this:

query = 
PartnerV3.query.join(PartnerAddress).order_by(PartnerAddress.distance(lat, 
lng)).paginate(1,10, False)

I can paginate the result, but it returns only the PartnerV3 object, i 
can't access the distance.

How do I access this distance property? 



  

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Select the hybrid method result on the query

2017-03-06 Thread Leonardo L. P. da Mata
Hello, thanks for the help.

This makes sense but it looks like that the value is calculated twice, one
in the query and the other accessing the property.

My idea is to have the result on the query return itself.



2017-03-06 18:31 GMT-03:00 mike bayer :

>
>
> On 03/06/2017 04:16 PM, Leonardo Mata wrote:
>
>> Hello, My applications does some ordering using the distance from
>> latitude and longitude haversine distance, i was able to calculate this
>> using @hybrid.method and @.*expression, but i can't output the
>> calculated distance:
>>
>> /class PartnerAddress(db.Model, WithTimestampsModel, SerializeMixin):/
>> //
>> /# Columns/
>> /id = db.Column(db.Integer(), primary_key=True, nullable=False)/
>> /
>> /
>> /partner_id = db.Column(/
>> /db.Integer(),/
>> /db.ForeignKey('partner.id'),/
>> /nullable=False/
>> /)/
>> /
>> /
>> /latitude = db.Column(db.Numeric(precision=9, scale=7),
>> nullable=False)/
>> /longitude = db.Column(db.Numeric(precision=10, scale=7),
>> nullable=False)/
>> /   /
>> /
>> /
>> /@hybrid_method/
>> /def distance(self, lat, lng):/
>> //
>> /return math.acos(math.cos(math.radians(self.latitude)) *
>> math.cos(math.radians(lat)) */
>> /   math.cos(math.radians(self.longitude) -
>> math.radians(lng)) +/
>> /   math.sin(math.radians(self.latitude)) *
>> math.sin(math.radians(lat))) * 6371/
>> /
>> /
>> /@distance.expression/
>> /def distance(cls, lat, lng):/
>> /return func.acos(func.cos(func.radians(cls.latitude)) *
>> func.cos(func.radians(lat)) */
>> / func.cos(func.radians(lng) -
>> func.radians(cls.longitude)) +/
>> / func.sin(func.radians(cls.latitude)) *
>> func.sin(func.radians(lat))) * 6371/
>> /
>> /
>> /
>> /
>> /class PartnerV3(db.Model, WithTimestampsModel,/
>> /SoftDeletableModel, SerializeMixin):/
>> //
>> /
>> /
>> /name = db.Column(db.String(128), nullable=False)/
>> //
>> /
>> /
>> /address = db.relationship(/
>> /'mustafar.partner.v3.models.address.PartnerAddress',/
>> /backref='partner',/
>> /uselist=False/
>> /)/
>>
>>
>> when querying like this:
>>
>> query =
>> PartnerV3.query.join(PartnerAddress).order_by(PartnerAddress
>> .distance(lat,
>> lng)).paginate(1,10, False)
>>
>> I can paginate the result, but it returns only the PartnerV3 object, i
>> can't access the distance.
>>
>> How do I access this distance property?
>>
>
> you have a PartnerV3 there so the PartnerAddress is on the .address
> property:
>
> query = 
> PartnerV3.query.join(PartnerAddress).order_by(PartnerAddress.distance(lat,
> lng))
>
>
> some_partner = query.first()
>
> partner_address = some_partner.address
> distance = partner_address.distance(lat, lng)
>
>
>
>
>
>
>>
>>
>>
>>
>> --
>> 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.
>> 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/to
> pic/sqlalchemy/4JKV8vS4jis/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.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Leonardo Luiz Padovani da Mata
barr...@gmail.com

"May the force be with you, always"
"Nerd Pride... eu tenho. Voce tem?"

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

Re: [sqlalchemy] Select the hybrid method result on the query

2017-03-06 Thread Leonardo L. P. da Mata
Thanks mike, that was a helpful explanation.


2017-03-06 18:59 GMT-03:00 mike bayer :

>
>
> On 03/06/2017 04:47 PM, Leonardo  L. P. da Mata wrote:
>
>> Hello, thanks for the help.
>>
>> This makes sense but it looks like that the value is calculated twice,
>> one in the query and the other accessing the property.
>>
>> My idea is to have the result on the query return itself.
>>
>>
> "lat" and "lng" here are variables that are in your program and are not
> related to the model you have.   So you're asking that a particular object
> be returned with additional values stuck onto it.
>
> The Session uses an identity map that ensures that an object of a
> particular primary key is only present once; if you make two queries which
> both return the same primary key, you get the same object back.
>
> If you did two queries with different values of "lat" / "lng" that both
> ultimately return the same PartnerAddress object, would the old values be
> erased?  It's not clear.
>
> Instead, this "distance" you're getting is really a value associated not
> just with the object but this specific query.   You can get it back by just
> adding it as a column:
>
>  query = session.query(PartnerV3, PartnerAddress.distance(lat,
> lng)).join(PartnerAddress).order_by(PartnerAddress.distance(lat, lng))
>
>
>  for partnerv3, distance in query:
>  print distance
>
>
>
>
>>
>> 2017-03-06 18:31 GMT-03:00 mike bayer > >:
>>
>>
>>
>> On 03/06/2017 04:16 PM, Leonardo Mata wrote:
>>
>> Hello, My applications does some ordering using the distance from
>> latitude and longitude haversine distance, i was able to
>> calculate this
>> using @hybrid.method and @.*expression, but i can't output the
>> calculated distance:
>>
>> /class PartnerAddress(db.Model, WithTimestampsModel,
>> SerializeMixin):/
>> //
>> /# Columns/
>> /id = db.Column(db.Integer(), primary_key=True,
>> nullable=False)/
>> /
>> /
>> /partner_id = db.Column(/
>> /db.Integer(),/
>> /db.ForeignKey('partner.id '),/
>> /nullable=False/
>> /)/
>> /
>> /
>> /latitude = db.Column(db.Numeric(precision=9, scale=7),
>> nullable=False)/
>> /longitude = db.Column(db.Numeric(precision=10, scale=7),
>> nullable=False)/
>> /   /
>> /
>> /
>> /@hybrid_method/
>> /def distance(self, lat, lng):/
>> //
>> /return math.acos(math.cos(math.radians(self.latitude)) *
>> math.cos(math.radians(lat)) */
>> /   math.cos(math.radians(self.longitude) -
>> math.radians(lng)) +/
>> /   math.sin(math.radians(self.la
>> titude)) *
>>
>> math.sin(math.radians(lat))) * 6371/
>> /
>> /
>> /@distance.expression/
>> /def distance(cls, lat, lng):/
>> /return func.acos(func.cos(func.radians(cls.latitude)) *
>> func.cos(func.radians(lat)) */
>> / func.cos(func.radians(lng) -
>> func.radians(cls.longitude)) +/
>> / func.sin(func.radians(cls.latitude)) *
>> func.sin(func.radians(lat))) * 6371/
>> /
>> /
>> /
>> /
>> /class PartnerV3(db.Model, WithTimestampsModel,/
>> /SoftDeletableModel, SerializeMixin):/
>> //
>> /
>> /
>> /name = db.Column(db.String(128), nullable=False)/
>> //
>> /
>> /
>> /address = db.relationship(/
>> /'mustafar.partner.v3.models.ad
>> dress.PartnerAddress',/
>>
>> /backref='partner',/
>> /uselist=False/
>> /)/
>>
>>
>> when querying like this:
>>
>> query =
>> PartnerV3.query.join(PartnerAddress).order_by(PartnerAddress
>> .distance(lat,
>> lng)).paginate(1,10, False)
>>
>> I can paginate the result, but it returns only the PartnerV3
>> object, i
>> can't access the distance.
>>
>> How do I access this distance property?
>>
>>
>> you have a PartnerV3 there so the PartnerAddress is on the .address
>> property:
>>
>> query =
>> PartnerV3.query.join(PartnerAddress).order_by(PartnerAddress
>> .distance(lat,
>> lng))
>>
>>
>> some_partner = query.first()
>>
>> partner_address = some_partner.address
>> distance = partner_address.distance(lat, lng)
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> SQLAlchemy -
>> The Python SQL Toolkit and Object Relational Mapper
>>
>> 

Re: [sqlalchemy] Select the hybrid method result on the query

2017-03-06 Thread mike bayer



On 03/06/2017 04:47 PM, Leonardo  L. P. da Mata wrote:

Hello, thanks for the help.

This makes sense but it looks like that the value is calculated twice,
one in the query and the other accessing the property.

My idea is to have the result on the query return itself.



"lat" and "lng" here are variables that are in your program and are not 
related to the model you have.   So you're asking that a particular 
object be returned with additional values stuck onto it.


The Session uses an identity map that ensures that an object of a 
particular primary key is only present once; if you make two queries 
which both return the same primary key, you get the same object back.


If you did two queries with different values of "lat" / "lng" that both 
ultimately return the same PartnerAddress object, would the old values 
be erased?  It's not clear.


Instead, this "distance" you're getting is really a value associated not 
just with the object but this specific query.   You can get it back by 
just adding it as a column:


 query = session.query(PartnerV3, PartnerAddress.distance(lat, 
lng)).join(PartnerAddress).order_by(PartnerAddress.distance(lat, lng))



 for partnerv3, distance in query:
 print distance






2017-03-06 18:31 GMT-03:00 mike bayer >:



On 03/06/2017 04:16 PM, Leonardo Mata wrote:

Hello, My applications does some ordering using the distance from
latitude and longitude haversine distance, i was able to
calculate this
using @hybrid.method and @.*expression, but i can't output the
calculated distance:

/class PartnerAddress(db.Model, WithTimestampsModel,
SerializeMixin):/
//
/# Columns/
/id = db.Column(db.Integer(), primary_key=True, nullable=False)/
/
/
/partner_id = db.Column(/
/db.Integer(),/
/db.ForeignKey('partner.id '),/
/nullable=False/
/)/
/
/
/latitude = db.Column(db.Numeric(precision=9, scale=7),
nullable=False)/
/longitude = db.Column(db.Numeric(precision=10, scale=7),
nullable=False)/
/   /
/
/
/@hybrid_method/
/def distance(self, lat, lng):/
//
/return math.acos(math.cos(math.radians(self.latitude)) *
math.cos(math.radians(lat)) */
/   math.cos(math.radians(self.longitude) -
math.radians(lng)) +/
/   math.sin(math.radians(self.la
titude)) *
math.sin(math.radians(lat))) * 6371/
/
/
/@distance.expression/
/def distance(cls, lat, lng):/
/return func.acos(func.cos(func.radians(cls.latitude)) *
func.cos(func.radians(lat)) */
/ func.cos(func.radians(lng) -
func.radians(cls.longitude)) +/
/ func.sin(func.radians(cls.latitude)) *
func.sin(func.radians(lat))) * 6371/
/
/
/
/
/class PartnerV3(db.Model, WithTimestampsModel,/
/SoftDeletableModel, SerializeMixin):/
//
/
/
/name = db.Column(db.String(128), nullable=False)/
//
/
/
/address = db.relationship(/
/'mustafar.partner.v3.models.ad
dress.PartnerAddress',/
/backref='partner',/
/uselist=False/
/)/


when querying like this:

query =

PartnerV3.query.join(PartnerAddress).order_by(PartnerAddress.distance(lat,
lng)).paginate(1,10, False)

I can paginate the result, but it returns only the PartnerV3
object, i
can't access the distance.

How do I access this distance property?


you have a PartnerV3 there so the PartnerAddress is on the .address
property:

query =
PartnerV3.query.join(PartnerAddress).order_by(PartnerAddress.distance(lat,
lng))


some_partner = query.first()

partner_address = some_partner.address
distance = partner_address.distance(lat, lng)










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

[sqlalchemy] Alembic or SQLAlchemy-Migrate

2017-03-06 Thread John Robson
For Migrations (in PostgreSQL), what you guys recommend? Alembic or 
SQLAlchemy-Migrate ?


Thank you.

--
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.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Alembic or SQLAlchemy-Migrate

2017-03-06 Thread mike bayer
sqlalchemy-migrate is legacy at this point, I'd say it's "unmaintained" 
but that's only because I've been made the "maintainer" by some kind of 
default (becausenobody else was maintaining it.  you get the idea).


so yes alembic is the standard now.

On 03/06/2017 07:15 PM, John Robson wrote:

For Migrations (in PostgreSQL), what you guys recommend? Alembic or
SQLAlchemy-Migrate ?

Thank you.



--
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.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Perfoming join on multiple tables dynamically

2017-03-06 Thread Simon King
On Mon, Mar 6, 2017 at 1:28 AM, Vijaya Sekar  wrote:
> Hello everyone,
>
> I have parent table which holds the primary keys of several child tables.The
> child table are got as a list . Using SQLalchemy ORM, how can I join
> multiple child tables to this parent?
>

Can you give an example of the kind of SQL that you are trying to
produce? I'm not sure what you mean when you say you want to join
multiple child tables. For example, this:

SELECT *
FROM parent p
JOIN child1 c1 ON p.childid = c1.id
JOIN child2 c2 ON p.childid = c2.id

...only makes sense if the same ID exists in both child tables.

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 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.
For more options, visit https://groups.google.com/d/optout.