Может быть, это поможет.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'OPTIONS': {
'options': '-c search_path=your_schema'
},
'NAME': 'your_name',
'USER': 'your_user',
'PASSWORD': 'your_password',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Я получаю ответ по следующей ссылке: http://blog.amvtek.com/posts/2014/Jun/13/accessing-multiple-postgres-schemas-from-django/
Using LEFT JOIN/IS NULL:
SELECT t.*
FROM TABLE_LIST t
LEFT JOIN TABLE_LOG tl ON tl.jid = t.jid
WHERE tl.jid IS NULL
Using NOT IN:
SELECT t.*
FROM TABLE_LIST t
WHERE t.jid NOT IN (SELECT tl.jid
FROM TABLE_LOG tl
GROUP BY tl.jid)
Using NOT EXISTS:
SELECT t.*
FROM TABLE_LIST t
WHERE NOT EXISTS(SELECT NULL
FROM TABLE_LOG tl
WHERE tl.jid = t.jid)
FYI
LEFT JOIN/IS NULL and NOT IN are equivalent in MySQL - they will perform the same, while NOT EXISTS is slower/less efficient. For more details: http://explainextended.com/2009/09/18/not-in-vs-not-exists-vs-left-join-is-null-mysql/
First off, you should be using an INNER JOIN on your existing query:
SELECT * FROM tablelist1
INNER JOIN tablelog2 ON (tablelist1.JID = tablelog2.JID)
WHERE tablelog2.UID = 'php var'
The way you're doing it you're getting all the rows from tablelist1, then going to extra trouble to exclude the ones that don't have a match in tablelog2. The INNER JOIN will do that for you, and more efficiently.
Secondly, to find for user "X" all the learnable-things that the user hasn't learned, do:
SELECT * FROM tablelist1
WHERE NOT EXISTS (SELECT JID FROM tablelog2 WHERE UID = 'X')