gpt4 book ai didi

sql - 运算符不是唯一的。无法选择最佳候选运算符。您可能需要添加显式类型转换

转载 作者:行者123 更新时间:2023-11-29 14:20:21 25 4
gpt4 key购买 nike

我有这个查询,它只选择两个日期之间的差异:

select date_part('day', 'toDate' - 'fromDate') from "Reservation" where "reservationID" = 1;

但这给了我这个错误:

operator is not unique. Could not choose a best candidate operator. You might need to add explicit type casts.

我该如何解决这个问题?

附言这就是我创建“预订”表的方式:

CREATE TABLE "Reservation"
(
"reservationID" serial NOT NULL,
"fromDate" timestamp without time zone NOT NULL DEFAULT '- infinity'::timestamp without time zone,
"toDate" timestamp without time zone NOT NULL DEFAULT '-infinity'::timestamp without time zone,
"staffID" integer NOT NULL DEFAULT 0,
"customerID" integer NOT NULL DEFAULT 0,
"roomID" integer NOT NULL DEFAULT 0,
CONSTRAINT "PK_public.Reservation" PRIMARY KEY ("reservationID"),
CONSTRAINT "FK_public.Reservation_public.Customer_customerID" FOREIGN KEY ("customerID")
REFERENCES "Customer" ("customerID") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT "FK_public.Reservation_public.Room_roomID" FOREIGN KEY ("roomID")
REFERENCES "Room" ("roomID") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT "FK_public.Reservation_public.Staff_staffID" FOREIGN KEY ("staffID")
REFERENCES "Staff" ("staffID") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE
)

最佳答案

你不能使用 ' 你需要 " 代替列名

select date_part('day', "toDate" - "fromDate") from "Reservation" where "reservationID" = 1;

关于sql - 运算符不是唯一的。无法选择最佳候选运算符。您可能需要添加显式类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29962253/

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