简体   繁体   English

错误:sqlalchemy.exc.ProgrammingError中“ N”或附近的语法错误

[英]ERROR: syntax error at or near “N” in sqlalchemy.exc.ProgrammingError

I have a query as 我有一个查询

query = '''
EXECUTE sp_executesql
N'select ex.b_id, b.code, 
    b.status as status, 
    ex.c_id, c.c_no, c.title as title,
    ex.s_id, s.s_no, s.title as s_title,
    ex.o_id, isnull(o.o_no, o._id) as o_no,
    ex.e_id, 
    ex.types
  from dbo.exercises ex
    left join XXXX o on
      (ex.b_id = o.b_id and ex.c_id = o.c_id
       and ex.s_id = o.s_id and ex.o_id = o.o_id)
    inner join YYYY b on (ex.b_id = b.b_id)
    inner join ZZZZ c on (ex.b_id = c.b_id and
      ex.c_id = c.c_id)
    inner join SSSS s on (ex.b_id = s.b_id and
      ex.c_id = s.c_id and ex.s_id = s.s_id)
  where
    -- cleaning criteria
    -- interesting data selection
    ex.b_id = @bid
  order by ex.b_id, ex.c_id, ex.s_id, ex.o_id,
    ex.o_no, ex.e_id',
N'@bid int',
@bid = ?;
'''

By using pandas read_sql , fetching data from databaase. 通过使用熊猫read_sql ,从databaase获取数据。

from sqlalchemy import create_engine 
from sqlalchemy import event 
import pandas as pd 
pd.read_sql(query, conn, params=params, chunksize=None)

It throws an error as sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) syntax error at or near "N" N'select ex.b_id, b.code, .. 它将错误抛出为sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError)语法错误,位于“ N”附近或附近 N'select ex.b_id,b.code,..

If you read the documentation , you will see that there are no string constants of the form N'...' in PostgresSQL. 如果您阅读了文档 ,将会发现PostgresSQL中没有N'...'形式的字符串常量。 All string constants have the same encoding, which is specified by the setting of client_encoding for your session. 所有字符串常量都具有相同的编码,这由会话的client_encoding设置指定。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)语法错误在“:”或附近 - sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) syntax error at or near “:” 在 Python 中执行原始 SQL 查询时出现问题:sqlalchemy.exc.programmingerror 在或附近出现语法错误 - Problem executing raw SQL query in Python: sqlalchemy.exc.programmingerror syntax error at or near sqlalchemy.exc.ProgrammingError:您的SQL语法有错误; 查看与MariaDB服务器版本对应的手册 - sqlalchemy.exc.ProgrammingError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version Django 中的 sqlalchemy.exc.ProgrammingError - sqlalchemy.exc.ProgrammingError in Django 烧瓶的sqlalchemy.exc.ProgrammingError - sqlalchemy.exc.ProgrammingError for flask (Flask)Heroku 错误:sqlalchemy.exc.ProgrammingError:(psycopg2.errors.DuplicateTable)关系“用户”已经存在 - (Flask) Heroku Error: sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DuplicateTable) relation "user" already exists 使用Flask和PostgresSQL时出错-sqlalchemy.exc.ProgrammingError:无法适应类型“ RowProxy” - Error using Flask and PostgresSQL - sqlalchemy.exc.ProgrammingError: can't adapt type 'RowProxy' sqlalchemy.exc.ProgrammingError :( ProgrammingError)无法调整类型'UUID' - sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt type 'UUID' 如何使用Flask-sqlalchemy.exc.ProgrammingError将数据插入Postgresql数据库? - How to insert data to postgresql database with flask - sqlalchemy.exc.ProgrammingError? 为什么我得到sqlalchemy.exc.ProgrammingError而不是sqlalchemy.exc.IntegrityError? - Why am I getting an sqlalchemy.exc.ProgrammingError rather than a sqlalchemy.exc.IntegrityError?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM