sqlalchemy

Python - SqlAlchemy: Filter query by great circle distance?

安稳与你 提交于 2020-12-25 05:19:57
问题 I am using Python and Sqlalchemy to store latitude and longitude values in a Sqlite database. I have created a hybrid method for my Location object, @hybrid_method def great_circle_distance(self, other): """ Tries to calculate the great circle distance between the two locations If it succeeds, it will return the great-circle distance multiplied by 3959, which calculates the distance in miles. If it cannot, it will return None. """ return math.acos( self.cos_rad_lat * other.cos_rad_lat * math

Why are Pandas and GeoPandas able to read a database table using a psycopg2 connection but have to rely on SQLAlchemy to write one?

孤街醉人 提交于 2020-12-25 01:30:53
问题 Context I just get into trouble while trying to do some I/O operations on some databases from a Python3 script. When I want to connect to a database, I habitually use psycopg2 in order to handle the connections and cursors. My data are usually stored as Pandas DataFrames and/or GeoPandas's equivalent GeoDataFrames. Difficulties In order to read data from a database table; Using Pandas: I can rely on its .read_sql() methods which takes as a parameter con , as stated in the doc: con :

Why are Pandas and GeoPandas able to read a database table using a psycopg2 connection but have to rely on SQLAlchemy to write one?

点点圈 提交于 2020-12-25 01:29:50
问题 Context I just get into trouble while trying to do some I/O operations on some databases from a Python3 script. When I want to connect to a database, I habitually use psycopg2 in order to handle the connections and cursors. My data are usually stored as Pandas DataFrames and/or GeoPandas's equivalent GeoDataFrames. Difficulties In order to read data from a database table; Using Pandas: I can rely on its .read_sql() methods which takes as a parameter con , as stated in the doc: con :

Why are Pandas and GeoPandas able to read a database table using a psycopg2 connection but have to rely on SQLAlchemy to write one?

核能气质少年 提交于 2020-12-25 01:29:27
问题 Context I just get into trouble while trying to do some I/O operations on some databases from a Python3 script. When I want to connect to a database, I habitually use psycopg2 in order to handle the connections and cursors. My data are usually stored as Pandas DataFrames and/or GeoPandas's equivalent GeoDataFrames. Difficulties In order to read data from a database table; Using Pandas: I can rely on its .read_sql() methods which takes as a parameter con , as stated in the doc: con :

Why are Pandas and GeoPandas able to read a database table using a psycopg2 connection but have to rely on SQLAlchemy to write one?

杀马特。学长 韩版系。学妹 提交于 2020-12-25 01:28:31
问题 Context I just get into trouble while trying to do some I/O operations on some databases from a Python3 script. When I want to connect to a database, I habitually use psycopg2 in order to handle the connections and cursors. My data are usually stored as Pandas DataFrames and/or GeoPandas's equivalent GeoDataFrames. Difficulties In order to read data from a database table; Using Pandas: I can rely on its .read_sql() methods which takes as a parameter con , as stated in the doc: con :

SQLAlchemy no password supplied error

时间秒杀一切 提交于 2020-12-24 02:42:44
问题 This is probably a silly error but I cannot seem to find a satisfying solution. When running db.create_all() , I got the following error. sqlalchemy.exc.OperationalError: (OperationalError) fe_sendauth: no password supplied None None My database link is set as 'postgresql://localhost/db_name' This worked fine on my Mac and Heroku, but is not OK on ubuntu (digitalocean). Any ideas what I might be doing wrong? 回答1: You probably just need to remove "localhost" from your connection string:

SQLAlchemy no password supplied error

别等时光非礼了梦想. 提交于 2020-12-24 02:40:05
问题 This is probably a silly error but I cannot seem to find a satisfying solution. When running db.create_all() , I got the following error. sqlalchemy.exc.OperationalError: (OperationalError) fe_sendauth: no password supplied None None My database link is set as 'postgresql://localhost/db_name' This worked fine on my Mac and Heroku, but is not OK on ubuntu (digitalocean). Any ideas what I might be doing wrong? 回答1: You probably just need to remove "localhost" from your connection string:

How to solve error “Operator 'getitem' is not supported on this expression” when using case()

我的梦境 提交于 2020-12-21 03:54:05
问题 I'm trying to convert the following SQL into SQLAlchemy: select t1.id, t1.field_A, max(case when t2.field_B = 1 then t2.field_C end) test_2_field_b_1, max(case when t2.field_B = 2 then t2.field_C end) test_2_field_b_2 from test_1 t1 inner join test_2 t2 on t2.field_A = t1.field_A group by t1.id, t1.field_A I've got as far as: qry = session.query( Test1.id_, Test2.field_A, func.max(case((Test2.field_B.__eq__(1), "Test2.field_C"))).label("test_2_field_b_1"), func.max(case((Test2.field_B.__eq__

How to solve error “Operator 'getitem' is not supported on this expression” when using case()

岁酱吖の 提交于 2020-12-21 03:52:46
问题 I'm trying to convert the following SQL into SQLAlchemy: select t1.id, t1.field_A, max(case when t2.field_B = 1 then t2.field_C end) test_2_field_b_1, max(case when t2.field_B = 2 then t2.field_C end) test_2_field_b_2 from test_1 t1 inner join test_2 t2 on t2.field_A = t1.field_A group by t1.id, t1.field_A I've got as far as: qry = session.query( Test1.id_, Test2.field_A, func.max(case((Test2.field_B.__eq__(1), "Test2.field_C"))).label("test_2_field_b_1"), func.max(case((Test2.field_B.__eq__

How to solve error “Operator 'getitem' is not supported on this expression” when using case()

一笑奈何 提交于 2020-12-21 03:52:37
问题 I'm trying to convert the following SQL into SQLAlchemy: select t1.id, t1.field_A, max(case when t2.field_B = 1 then t2.field_C end) test_2_field_b_1, max(case when t2.field_B = 2 then t2.field_C end) test_2_field_b_2 from test_1 t1 inner join test_2 t2 on t2.field_A = t1.field_A group by t1.id, t1.field_A I've got as far as: qry = session.query( Test1.id_, Test2.field_A, func.max(case((Test2.field_B.__eq__(1), "Test2.field_C"))).label("test_2_field_b_1"), func.max(case((Test2.field_B.__eq__