在相同的db中铸造时工作良好,但在使用deeplink时失败
在同一数据库中正常工作(通过此查询获得结果):
SELECT id,
total_inventory,
hotel_id,
( room_type -> 'id' ) :: bigint AS room_type_id,
created_by,
created_date,
modified_by,
modified_date
FROM hotel_inventory;
与其他数据库连接时不工作(使用deeplink)(此查询出错):
INSERT INTO hotel_inventory
(
id,
total_inventory,
hotel_id,
room_type_id,
created_by,
created_date,
modified_by,
modified_date
)
SELECT *
FROM dblink('demopostgres', 'SELECT id, total_inventory, hotel_id, (room_type -> 'id')::bigint as room_type_id, created_by, created_date, modified_by, modified_date FROM hotel_inventory')
AS data(id bigint, total_inventory integer, hotel_id bigint, room_type_id bigint, created_by jsonb, created_date timestamp without time zone, modified_by jsonb, modified_date timestamp without time zone);
错误:
ERROR: syntax error at or near "id"
LINE 3: ...ECT id, total_inventory, hotel_id, (room_type -> 'id')::bigi...
^
SQL state: 42601
Character: 221
1条答案
按热度按时间gkl3eglg1#
您需要将单引号加倍以避免此类错误:
问题是一个简单的解析错误。单引号结束字符串——因此出现错误。双单引号是将单引号放入字符串中的标准方法,尽管不同的数据库通常支持其他方法(例如反斜杠)。