Code

Opened 8 years ago

Closed 5 years ago

Last modified 4 years ago

#1208 closed defect (duplicate)

db_table with schema name does not work on PostgreSQL

Reported by: slamb@… Owned by: adrian
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: UI/UX:

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

Attachments (0)

Change History (6)

comment:1 Changed 8 years ago by adrian

See also [1051].

comment:2 Changed 8 years ago by jacob

  • Resolution set to duplicate
  • Status changed from new to closed

duplicate of #1051

comment:3 Changed 5 years ago by jxh

  • Resolution duplicate deleted
  • Status changed from closed to 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 Changed 5 years ago by ramiro

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 Changed 5 years ago by russellm

  • Resolution set to duplicate
  • Status changed from reopened to closed

Agreed. Dupe of #6148.

comment:6 Changed 4 years ago by akaihola

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.