gpt4 book ai didi

database - 尝试使用 || 在 RAISE() 函数中进行连接导致语法错误

转载 作者:搜寻专家 更新时间:2023-10-30 23:32:26 25 4
gpt4 key购买 nike

relevant documentation

我正在尝试创建一个触发器,用于捕获外键 (viewings.location) 与 Places 表 (places.location) 中现有主键不对应的 Viewings 表中的插入。据我所知,逻辑按预期工作。但是,我的问题来自于尝试将尝试的值连接到 raise 函数中的错误消息中。这是不允许的吗?

create trigger catchForeignKeyError BEFORE INSERT ON VIEWINGS
BEGIN
SELECT CASE
WHEN NEW.location NOT IN (SELECT PLACES.location FROM PLACES) THEN
RAISE(ABORT, 'Error: Insert into the VIEWINGS table references location '''||NEW.location||''' that is not found in the PLACES table.')
END;
END;

最佳答案

在SQLite语法中,RAISE()表达式的第二个参数不是字符串而是名称:

RAISE(ABORT, some_error)

标识符可以用双引号引起来,由于历史原因,SQLite accepts a string (with single quotes) where an identifier is expected , 但它必须是单个字符串,而不是其他值组成的字符串表达式:

RAISE(ABORT, "some error")

除了为此创建用户定义的函数之外,没有任何机制可以将动态值获取到错误消息中。

关于database - 尝试使用 || 在 RAISE() 函数中进行连接导致语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47598862/

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