#1208 closed defect (duplicate)
db_table with schema name does not work on PostgreSQL
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I give Django a db_table of "loadtest.machine", it passes to PostgreSQL "loadtest.machine", in quotes. PostgreSQL wants "loadtest"."machine". There needs to be some way of passing in a schema-qualified table name, such as:
- pass in the latter, at the expense of not supporting an actual '.' in the name).
- support a db_schema attribute, maybe, so there's no ambiguity.
My code used to work, but Django added some quoting.
Here's an example of the errors pgsql gives:
loadtest=# select count(*) from "loadtest"."experiment"; count ------- 25 (1 row) loadtest=# select count(*) from "loadtest.experiment"; ERROR: relation "loadtest.experiment" does not exist
Change History (6)
comment:1 by , 19 years ago
comment:3 by , 16 years ago
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
1051 et seq don't quite address this concern. They only want to let you set the search_path, once per application or per database connection. If your application needs to talk to an existing postgresql database with data in multiple schemas, you need to be able to express table names as 'a.b' and have them appear as 'a'.'b' in SQL. In fact, search_path need never be used.
comment:4 by , 16 years ago
I'd say this ticket can be re-closed. #6148 is the ticket tracking implementation of a generic support for specifying DB schemas for model tables feature.
comment:5 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
Agreed. Dupe of #6148.
comment:6 by , 15 years ago
For anyone looking for a quick work-around, MariusBoo noted that you can define your table like this:
db_table = '"django"."company"'
This will fool the quote function to think that your table is properly quoted. This also means that you have to specify the schema for each table manually.
I just verified that this solution works with r10837 and r11802 and PostgreSQL 8.3.8.
See also [1051].