Opened 9 years ago

Last modified 4 years ago

#16376 new New feature

Support for database links

Reported by: stephane.benchimol@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: oracle postgres
Cc: ian.g.kelly@…, diegobz, anssi.kaariainen@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


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:


It should be:


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 (6)

comment:1 Changed 9 years ago by Russell Keith-Magee

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 5 years ago by johnhomes (previous) (diff)

comment:2 Changed 9 years ago by stephane.benchimol@…

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 Changed 9 years ago by Ian Kelly

Cc: ian.g.kelly@… added

comment:4 Changed 8 years ago by diegobz

Cc: diegobz added

comment:5 Changed 8 years ago by Anssi Kääriäinen

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 Changed 4 years ago by Asif Saifuddin Auvi

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