Python2.6的Psycopg2完全外部连接

Python2.6的Psycopg2完全外部连接,python,postgresql,python-2.6,psycopg2,Python,Postgresql,Python 2.6,Psycopg2,我对使用psycopg2与postgreSQL数据库交互是一个全新的概念。我正在尝试执行完全外部联接,但找不到任何文档来帮助我执行该命令。以下是我在Python 2.6中尝试的内容: cursor.execute(""" SELECT spl.id, spl.index, spl.d_id, spl.p_id, spl.pattern, spe.id, spe.index, spe.d_id, spe.p_id, FROM s_phr

我对使用psycopg2与postgreSQL数据库交互是一个全新的概念。我正在尝试执行完全外部联接,但找不到任何文档来帮助我执行该命令。以下是我在Python 2.6中尝试的内容:

cursor.execute("""
SELECT spl.id,
   spl.index,
   spl.d_id,
   spl.p_id,
   spl.pattern,
   spe.id,
   spe.index,
   spe.d_id,
   spe.p_id,       
FROM s_phrase_label spl
FULL OUTER JOIN s_pattern_extraction spe
ON spl.thread.id = spe.id
   AND spl.d_id = spe.d_id,
   AND spl.index = spe.index
""")
但我总是出错。提前感谢您的帮助

编辑:错误是

ProgrammingError: syntax error at or near "AND"
LINE 14:                        AND spl.index = spe.index

您缺少一个逗号:

spl.d_id,
   spl.p_id,
   spl.pattern  //Right here
spe.id,

不应将逗号放在<代码>中使用的逻辑表达式的中间,其中子句:

...
AND spl.d_id = spe.d_id, -- This is an error.
AND spl.index = spe.index
...

此外,这与psycopg无关:这是一个SQL语法错误。

@ztoolson由于我没有可用的模式,您是否也希望键入
spl.thread\u id
而不是
spl.thread.id
?@ztoolson解决了问题,或者您看到了更多问题?我建议自己进行查询,并尝试在DB控制台/应用程序中运行它。有几个很好的工具,松鼠,蟾蜍,或PGAdmin等等。这解决了这个问题!谢谢