I am trying to filter by lat/long in a table of sites I have to prevent duplicate entries. However, I'm finding that filtering for these columns doesn't find a match that I would expect. Does anyone know why this filter might not be working? Thanks for any help
I am running these queries and comparing the results:
data_dict = {'lat':33.7838, 'lng':-117.225}
filter_test = session.query(Sites.lat, Sites.lng).filter(
and_(
Sites.lat == data_dict['lat'],
Sites.lng == data_dict['lng']
)
).all()
print(f'Filter test: {filter_test}')
no_filter = session.query(Sites).all()
for rec in no_filter:
if rec.lat == data_dict['lat']:
print(rec.country, rec.lat, rec.lng)
print(rec.lat == data_dict['lat'])
The result from the first section (Querying with filtering) prints:
Filter test: []
However, the result of the second section (Querying all THEN filtering) prints:
United States 33.7838 -117.225
True
United States 33.7838 -117.225
True
My Sites table in SqlAlchemy looks like this:
class Sites(Base):
__tablename__ = "sites"
get_table_name = get_table_name
country = Column(String(15))
zipcode = Column(Integer)
lat = Column(Float)
lng = Column(Float)
Here is an image that shows a section of my sites table, with the records I am looking to filter for included:
