gpt4 book ai didi

postgresql - 错误 : zero-length delimited identifier at or near "" ""LINE 1: DELETE FROM "regions"WHERE "regions" ."" = $1

转载 作者:行者123 更新时间:2023-11-29 11:09:10 24 4
gpt4 key购买 nike

我使用 Rails 4.1 和 Postgresql(带有 PG gem)作为我的数据库。我有一个非常多的协会,从公司到省,有一个称为区域的连接表。现在显然区域表没有主键,因为我使用了 { :id => false }。但是,当我尝试使用 depending destroy 或只是简单地在区域对象上调用 destroy 时,我收到此错误:

 ERROR:  zero-length delimited identifier at or near """"
LINE 1: DELETE FROM "regions" WHERE "regions"."" = $1

我知道问题是由于区域表缺少主键引起的。奇怪的是,如果我将主键添加回表中,销毁工作正常并且没有错误。但是,如果我从表中删除主键,错误又会回来。我知道这与 postgres 有关,但我不知道如何在不向我的区域表添加主键列的情况下解决这个问题。

这是实际的查询

[DEBUG] [AdminUser Load (0.4ms)  SELECT  "admin_users".* FROM "admin_users"  WHERE "admin_users"."id" = 1  ORDER BY "admin_users"."id" ASC LIMIT 1] (pid:29655)
[DEBUG] [Province Load (0.2ms) SELECT "provinces".* FROM "provinces" WHERE "provinces"."id" = $1 LIMIT 1 [["id", 5]]] (pid:29655)
[DEBUG] [ (0.1ms) BEGIN] (pid:29655)
[DEBUG] [Region Load (0.3ms) SELECT "regions".* FROM "regions" WHERE "regions"."province_id" = $1 [["province_id", 5]]] (pid:29655)
[ERROR] [PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: DELETE FROM "regions" WHERE "regions"."" = $1

最佳答案

您需要单引号而不是双引号将空字符串括起来,双引号作为定界标识符,并且“”不是有意义的标识符。

尝试:

WHERE 'regions'.'' = $1

或至少:

WHERE "regions".'' = $1

关于postgresql - 错误 : zero-length delimited identifier at or near "" ""LINE 1: DELETE FROM "regions"WHERE "regions" ."" = $1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23165282/

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