from table country in postgres :
id country_code country_desc
1 US United States
2 GB United Kingdom
3. GR Greece
4 CA Canada
i retrieve column country_code using sqlalchemy.My db is set to utf-8:
engine = sql.create_engine(connectionString)
countries = engine.execute('select country_code from country')
for country in countries:
print(country)
which returns:
('US',)
('GB',)
('GR',)
('CA',)
instead of
US
GB
GR
CA
I have no idea why.
asked Jan 24, 2020 at 22:07
Bonzay
7502 gold badges12 silver badges33 bronze badges
2 Answers 2
Have you tried something like:
countries.country_code or countries.["country_code"]
answered Jan 24, 2020 at 22:14
Saul Ramirez
4262 silver badges10 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
engine = sql.create_engine(connectionString)
countries = engine.execute('select country_code from country')
for country in countries:
print(country[0])
did the job
answered Jan 24, 2020 at 22:19
Bonzay
7502 gold badges12 silver badges33 bronze badges
Comments
default