if you are using SA strictly for its connection pool, the pool
returns regular psycopg2 connections to you (well, inside a proxy)
with which you can do whatever psycopg2-specific stuff you want.
however if you are using SA's generated SQL and/or ORM, these systems
abstract away the underlying concept of the "cursor" so that its
generally dealt with behind the scenes. the Connection object, which
you can get most commonly by calling engine.connect(), contains a
reference to the "real" connection that it maintains which you can
access as connection.connection. so at that point, you have your
actual postgres connection (well, the proxied version, but its
transparent). you can use that connection to execute straight DBAPI
code like you have below.
if you are looking to use a named cursor within generated SQL and/or
ORM (session) flushes and stuff like that, the API is not really
there for that stuff. you can create ResultProxy objects with a
cursor, like this:
connection = engine.connect()
dbapi_conn = connection.connection
cursor = dbapi_conn.cursor("test")
result = cursor.execute("select * from table")
result_proxy = ResultProxy(engine, connection, cursor, None)
but thats about as much as you can do.
there usually isnt much need to actually deal with a cursor since the
concept of working with SA connections is at a higher level than
straight DBAPI. if you had some optimization in mind using named
cursors, for example, SA's query execution and ORM would probably
have little ability to take advantage of it.
so the main question is, what do you need named cursors for ?
On Jan 8, 2007, at 9:14 AM, Michele Petrazzo wrote:
Hi,
I'm trying to use the "named cursor" function provided by postgres and
psycopg2 driver, but I can't figure out how to do it.
In "direct" sql, I can do:
con = psycopg2.connect('user=test password=test dbname=test')
cur = con.cursor("test")
cur.execute("SELECT * FROM test")
Is there a method to do it with sqlalchemy? On the doc I don't find
anything.
Thanks,
Michele
----------------------------------------------------------------------
---
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to
share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?
page=join.php&p=sourceforge&CID=DEVDEV________________________________
_______________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---