gpt4 book ai didi

sqlite - sqlite3中没有这样的列错误

转载 作者:行者123 更新时间:2023-12-03 15:48:20 26 4
gpt4 key购买 nike

我正在尝试将值插入到我的表中,但出现“没有此类列”错误。我正在搜索并发现在大多数情况下是因为它们缺少引号,但我似乎有它们。谁能指出我正确的方向?

CREATE TABLE students (
id INTEGER PRIMARY KEY,
first_name VARCHAR(255),
last_name VARCHAR(255),
grade INT,
passing BOOLEAN,
teacher_id INT,
FOREIGN KEY (teacher_id) REFERENCES teachers(id)
);

INSERT INTO students (first_name, last_name, grade, passing, teacher_id)
VALUES (‘Ted’, ‘Mosby’, 84, true, 2);

Error: no such column: ‘Ted’

最佳答案

使用 ' 而不是 '1 而不是 true:

SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).

INSERT INTO students (first_name, last_name, grade, passing, teacher_id) 
VALUES ('Ted', 'Mosby', 84, 1, 2);

如果您想使用变量,请使用相同的引号:

INSERT INTO students (first_name, last_name, grade, passing, teacher_id) 
VALUES ('$firstName', '$lastName', 84, 1, 2);

SqlFiddleDemo

输出:

╔═════╦═════════════╦════════════╦════════╦══════════╦════════════╗
║ id ║ first_name ║ last_name ║ grade ║ passing ║ teacher_id ║
╠═════╬═════════════╬════════════╬════════╬══════════╬════════════╣
║ 1 ║ Ted ║ Mosby ║ 84 ║ 1 ║ 2 ║
╚═════╩═════════════╩════════════╩════════╩══════════╩════════════╝

关于sqlite - sqlite3中没有这样的列错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36829038/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com