psycopg2.ProgrammingError:语法错误或附近

时间:2017-09-21 14:59:33

标签: python-3.x psycopg2 psql

我正在尝试使用以下代码执行01-plan_detail.sql

    with db.cursor() as c:
    logging.info('Combining results for 5500 long and short form to load plan details')
    with open(os.path.join(os.path.dirname(__file__),
        '../resources/sql/01-plan_detail.sql'), 'rb') as io:
        c.execute(io.read())
        drain_notices(db, logging)

每次运行此操作时,我都会在execute()上收到以下错误:

Traceback (most recent call last):
  File "./bin/00-laod_plan_detail.py", line 38, in <module>
    c.execute(io.read())
psycopg2.ProgrammingError: syntax error at or near "drop"
LINE 1: drop table if exists lf5500 cascade

01-plan_detail.sql的内容看起来接近这个:

drop table if exists lf5500 cascade;
create temp table lf5500 as (
select * from from tableA lf
  left join tableB h
    on lf.ack_id = h.ack_id
)
distributed by (ack_id);

drop table if exists sf5500 cascade;
create temp table sf5500 as (
select * from from tableC sf
  left join tableD i
    on sf.bus_code = i.bus_code
)
distributed by (ack_id);

-- Combine results to create plan_detail table
drop table if exists f_5500_output_plan_detail cascade;
create table f_5500_output_plan_detail as (
select * from lf5500
union 
select * from sf5500
)
distributed by (ack_id);

如果我单独执行sql脚本,它运行正常,没有错误。但是,当我尝试使用Python中的psycopg2执行它时,它会抛出错误。

版本:psql 8.2.15 | python 3.6.0 | psycopg2 2.6.1

有人可以看看并帮我解决问题吗? 感谢您的帮助!

0 个答案:

没有答案