Opened 13 years ago

Last modified 8 months ago

#16376 new New feature

Support for database links

Reported by: stephane.benchimol@… 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 Russell Keith-Magee, 13 years ago

Triage Stage: UnreviewedAccepted

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).

Last edited 10 years ago by johnhomes (previous) (diff)

comment:2 by stephane.benchimol@…, 13 years ago

Keywords: postgres added
Summary: [oracle] Support for database linksSupport 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 Erin Kelly, 13 years ago

Cc: ian.g.kelly@… added

comment:4 by diegobz, 13 years ago

Cc: diegobz added

comment:5 by Anssi Kääriäinen, 13 years ago

Cc: anssi.kaariainen@… added

I am currently working on #6148, and I think this could be relatively easy to support if the #6148 work gets completed. Just another syntax for the FROM entry.

If this gets implemented, db_link should imply managed = False.

comment:6 by Asif Saifuddin Auvi, 8 years ago

Version: 1.3master

comment:7 by Ülgen Sarıkavak, 8 months ago

Cc: Ülgen Sarıkavak added
Note: See TracTickets for help on using tickets.
Back to Top