On 06/28/2016 06:50 AM, 'Moritz Liebelt' via sqlalchemy wrote:
Hi,
I will read all informations out of my table building.
In my opinion the connection is successfull but it cannot find the table!

My code:

|
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy import MetaData
from sqlalchemy import select
import cx_Oracle
engine =
create_engine('postgresql://postgres:postgres@localhost:5432/3DCityDB_kreis_boeblingen',
echo = True)
metadata = MetaData(bind=engine)
conn = engine.connect()

s = select([building.c.id])

result = conn.execute(s)
for row in result:
 print(row)
|

Can anyone please help me?

*error-message: NameError: name 'building' is not defined!*

In Python, every name we refer to has to come from somewhere, either from an import, an assignment (e.g. x = y), or a def or class definition. In this case we are looking to use assignment. You're looking to use a Table object here, so we need to make one. We also want to make sure it has column objects that match up what's in our database, so we will use a feature called reflection.

Add this line right below your "MetaData" line and this will work:

building = Table('building', metadata, autoload_with=engine)

now you can work with "building.c.id".



*
*
But it is one tablename out of my database...

--
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
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

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

Reply via email to