gpt4 book ai didi

sql - 尽管引用了表,但列名不明确

转载 作者:行者123 更新时间:2023-12-04 09:58:32 24 4
gpt4 key购买 nike

尽管在一个非常相似的函数中没有这个问题,但我似乎在这个函数中遇到了这个问题,并且在这个特定的上下文中找不到关于这个问题的任何建议(我可以理解,哈哈)。如果有人可以提供任何建议或引用,将不胜感激。

错误:“列引用“customerid”不明确”

CREATE OR REPLACE FUNCTION update_FlightBooking(INTEGER, INTEGER, INTEGER, INTEGER, CHAR(1), TIMESTAMP, DECIMAL)
RETURNS TABLE
(
BookingID INTEGER,
CustomerID INTEGER,
FlightID INTEGER,
NumSeats INTEGER,
Status CHAR(1),
BookingTime TIMESTAMP,
TotalCost DECIMAL
) AS $$

BEGIN
IF NOT EXISTS (SELECT CustomerID FROM FlightBooking WHERE FlightBooking.CustomerID = $2) THEN
INSERT INTO FlightBooking VAlUES($1, $2, $3, $4, $5, $6, $7);

ELSE
UPDATE FlightBooking AS fb
SET NumSeats = NumSeats + $4, TotalCost = TotalCost + $7
WHERE fb.CustomerID = $2;
END IF;

IF NOT EXISTS (SELECT CustomerID FROM LeadCustomer WHERE LeadCustomer.CustomerID = $2) THEN
ROLLBACK;
END IF;

IF (check_Seats($3) < 0) THEN
ROLLBACK;
END IF;

RETURN QUERY
SELECT fb.BookingID, fb.CustomerID, fb.FlightID, fb.NumSeats, fb.Status, fb.BookingTime, fb.TotalCost
FROM FlightBooking AS fb WHERE fb.CustomerID = $1;
END;
$$
LANGUAGE plpgsql;

最佳答案

https://www.postgresql.org/docs/9.5/plpgsql-implementation.html

By default, PL/pgSQL will report an error if a name in a SQL statement could refer to either a variable or a table column. You can fix such a problem by renaming the variable or column, or by qualifying the ambiguous reference, or by telling PL/pgSQL which interpretation to prefer.



这适用于 customerIdIF NOT EXISTS (SELECT CustomerID ...

关于sql - 尽管引用了表,但列名不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61873924/

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