Opened 13 years ago
Last modified 9 months ago
#16376 new New feature
Support for database links
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | oracle postgres |
Cc: | ian.g.kelly@…, diegobz, anssi.kaariainen@…, Ülgen Sarıkavak | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently, Oracle with Django do not support database links (see Oracle documentation)
It's used this way in SQL:
select count(*) from "MY_TABLE"@"MY_DBLINK";
With Django, I tried to passe it through the db_name
class MyObject(models.Model): class Meta: managed = False db_table = u'"MY_TABLE"@"MY_DBLINK"'
However, when it comes to write sql, Django use db_table to specify the column names. Using db link, the generated command is not valid:
SELECT "MY_TABLE"@"MY_DBLINK"."COLUMN1", "MY_TABLE"@"MY_DBLINK"."COLUMN2" FROM "MY_TABLE"@"MY_DBLINK"
It should be:
SELECT "MY_TABLE"."COLUMN1"@"MY_DBLINK", "MY_TABLE"."COLUMN2"@"MY_DBLINK" FROM "MY_TABLE"@"MY_DBLINK"
I think it worth to add a new db_link Meta option, eg.
class MyObject(models.Model): class Meta: managed = False db_table = u'MY_TABLE' db_link = u'MY_DBLINK'
A workaround could be to define a new database access in Django settings. However, I guess in some cases, the remote database could be reached only from the bridge - not directly from Django application. That's why this options should be needed.
Change History (7)
comment:1 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 13 years ago
Keywords: | postgres added |
---|---|
Summary: | [oracle] Support for database links → Support for database links |
After few researches, it appears this function is not only Oracle-specific, but exists also in Postgresql (see Postgresql documentation) -- and maybe more databases ?
However, with Postgres, the approach is slightly different, because it has to encapsulate the query using dblink function, eg.
select * from dblink('dbname=MY_DBLINK', 'select count(*) from "MY_TABLE"')
comment:3 by , 13 years ago
Cc: | added |
---|
comment:4 by , 13 years ago
Cc: | added |
---|
comment:5 by , 13 years ago
Cc: | added |
---|
comment:6 by , 8 years ago
Version: | 1.3 → master |
---|
comment:7 by , 9 months ago
Cc: | added |
---|
See #6148 for a vaguely related ticket. Based on the documentation provided, it also seems like there's crossover here with the feature request for cross-database joins (documented as not being supported in #13216)
As for the API approach, I'm not wild about the idea of adding a Meta option for an Oracle-specific feature. It feels to me like there should be some way to tie this to routing and the underlying database definition (i.e., the link is a feature of the database connection, not of the table itself).