创建一个以
使用存储过程执行带有WHERE
子句的DELETE
语句时,该子句似乎会被忽略。
复制步骤:
创建BQ表
CREATE TABLE `[project].[dataset].test` (
email STRING NOT NULL,
providerId STRING NOT NULL
);
添加测试数据
insert into `[project].[dataset].test` (email, providerId) values ('test.email@gmail.com', 'test1');
insert into `[project].[dataset].test` (email, providerId) values ('test.email@gmail.com', 'test2');
创建一个以email
和providerId
为输入的存储过程
CREATE OR REPLACE PROCEDURE `[project].[dataset].RemovePermission`(IN providerId STRING, IN email STRING)
BEGIN
DELETE FROM `[project].[dataset].test` p
WHERE p.email = email
AND p.providerId = providerId;
END;
执行存储过程
CALL [project].[dataset].RemovePermission('test1', 'test.email@gmail.com`)
请注意,响应已删除2行,测试表现在为空。
相反,如果手动执行删除操作,如下所示,则只删除1行——这是正确的行为。
DELETE FROM `[project].[dataset].test` p
WHERE p.email = 'test.email@gmail.com'
AND p.providerId = 'test1';
我做错了什么?
参数名称email, providerId
是"冲突的";列名称为email, providerId
,因此WHERE p.email = email AND p.providerId = providerId
始终为true
只需更改参数名称,它就会按预期工作。类似的东西
CREATE OR REPLACE PROCEDURE `project.dataset.RemovePermission`(IN Id STRING, IN txt STRING)
BEGIN
DELETE FROM `project.dataset.test` p
WHERE p.email = txt
AND p.providerId = Id;
END;