You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's too tricky to get this right. It'll lead to surprises because:
1. It breaks with transaction pooling.
2. Interaction with `SET LOCAL` is strange. A `SET` command after
a `SET LOCAL` overrides it.
I already shot myself in the foot twice since implementing this.
By default, a connection operates in the ``public`` schema. The schema offers a connection scoped to that schema that sets the Postgres ``search_path`` to only search within that schema.
162
-
163
-
.. warning::
164
-
165
-
This can be abused to manage Django models in a custom schema. This isnot a supported workflow and there might be unexpected issues from attempting to do so.
166
-
167
-
.. warning::
168
-
169
-
Do not use this in the following scenarios:
170
-
171
-
1. You access the connection from multiple threads. Scoped connections are **NOT** thread safe.
172
-
173
-
2. The underlying database connection is passed through a connection pooler in transaction pooling mode.
174
-
175
-
.. code-block:: python
176
-
177
-
from psqlextra.schema import PostgresSchema
178
-
179
-
schema= PostgresSchema.create("myschema")
180
-
181
-
with schema.connection.cursor() as cursor:
182
-
# table gets created within the `myschema` schema, without
183
-
# explicitly specifying the schema name
184
-
cursor.execute("CREATE TABLE mytable AS SELECT 'hello'")
185
-
186
-
with schema.connection.schema_editor() as schema_editor:
0 commit comments