Hi Michael,
As a very quick test to see if I could make things work, I created a new
postgres user and set that user's search_path to just '"$user"' (since it can't
be empty, but as there are no tables with the user's name, that's effectively
what it is). My toy example worked.
On May 18, 2012, at 5:10 PM, Michael Bayer wrote:
> If you've created all your Table objects with an explicit "schema"
> definition, you shouldn't need anything in your search path - technically not
> even "public". If the issue is that your database connection defaults to a
> certain search path, change the search path just within your SQLAlchemy
> application to not include defaults. A "connect" event listener can achieve
> this.
I'm trying to avoid creating a separate user just for scripts that use SA and
it sounds like your suggestion above should address this, but I'm a little
stuck on how that will work. This is what I have:
def my_on_connect(dbapi_con, connection_record):
print "New DBAPI connection:", dbapi_con
# ??? execute query 'SET search_path TO "$user"'
I call
listen(Pool, 'connect', my_on_connect)
very early in my code, which seems to be properly called. Can you help me fill
in the missing line? If I understand things correctly, then this hook will set
the search path for the lifetime of any connection made to the database,
regardless of what the user has set otherwise.
I also tried something like this:
http://www.mail-archive.com/[email protected]/msg09859.html
but that didn't work. I first make the database connection and then later
define my table classes through autoload, and it seemed to have a problem with
that order (I think I got a "table not found" error upon metadata.reflect().)
Thanks again for all your help - I'm finally seeing the light at the end of
this tunnel!
Cheers,
Demitri
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
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.