Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

sqlite - can't create a table with TEXT datatype SQLite3

I'm getting this error everytime I try to make a TEXT datatype:

values TEXT )"""
    sqlite3.OperationalError: near "values": syntax error

and this is my code

cursor.execute("""CREATE TABLE outliers (
            DUT integer,
            time integer,
            params TEXT,
            values TEXT )"""
    )

can someone help me? I'm having a lot of difficulties trying to find out why


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

values is a reserved word in SQL (as in insert into mytable VALUES (1, 2, 3)). The best approach would be to choose a name that isn't a reserved word, such as outlier_values:

cursor.execute("""CREATE TABLE outliers (
            DUT integer,
            time integer,
            params TEXT,
            outlier_values TEXT )"""
    )

If this isn't an option, you could escape the name with double quotes ("):

cursor.execute("""CREATE TABLE outliers (
            DUT integer,
            time integer,
            params TEXT,
            "values" TEXT )"""
    )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...