Opened 18 years ago

Closed 15 years ago

Last modified 14 years ago

#1208 closed defect (duplicate)

db_table with schema name does not work on PostgreSQL

Reported by: slamb@… 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 Adrian Holovaty, 18 years ago

See also [1051].

comment:2 by Jacob, 18 years ago

Resolution: duplicate
Status: newclosed

duplicate of #1051

comment:3 by jxh, 15 years ago

Resolution: duplicate
Status: closedreopened

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 Ramiro Morales, 15 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 Russell Keith-Magee, 15 years ago

Resolution: duplicate
Status: reopenedclosed

Agreed. Dupe of #6148.

comment:6 by Antti Kaihola, 14 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.

Note: See TracTickets for help on using tickets.
Back to Top