简体   繁体   English

OperationalError:“:1”附近:SQLite中的语法错误

[英]OperationalError: near “:1”: syntax error in SQLite

I have this error. 我有这个错误。

My Table column names are as followed after i performed join and union: 执行联接和联合后,我的表列名称如下所示:

['A','B','C','B:1','D','B:2','E']

In order to drop/rename the Table columns, I executed this query: 为了删除/重命名Table列,我执行了以下查询:

query = '''
        CREATE TABLE New_Table
        ['A','B_a','C','B_b','D','B_c','E']
        '''
query1 = '''
        INSERT INTO New_Table
        ('A','B_a','C','B_b','D','B_c','E')
        SELECT A, B, C, B:1, D, B:2, E
        FROM Table
        '''

import sqlite3
conn = sqlite3.connect('dbase_Sqlite')  # create or open db file
curs = conn.cursor()
curs.execute(query)
conn.commit()
curs.execute(query1)
conn.commit()

I got this error: 我收到此错误:

OperationalError: near ":1": syntax error

Apparently the ":1" and ":2" were added by the sqlite JOIN or UNION earlier. 显然,sqlite JOIN或UNION早先添加了“:1”和“:2”。 How should i deal with it? 我应该如何处理?

I found an answer here, escaping the column names by giving "" to all column names in the query. 我在这里找到了答案,通过在查询中为所有列名加上“”来转义列名。 It works. 有用。

query1 = '''
        INSERT INTO New_Table
            ('A','B_a','C','B_b','D','B_c','E')
        SELECT "A", "B", "C", "B:1", "D", "B:2", "E"
        FROM Table
        '''

Reference: https://blog.christosoft.de/2012/10/sqlite-escaping-table-acolumn-names/ 参考: https : //blog.christosoft.de/2012/10/sqlite-escaping-table-acolumn-names/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM