如何獲取臨時變量中的行並處理/使用其字段? 請參閱開始部分,我需要獲取帳戶信息,進行一些計算,例如我需要在帳戶餘額方法中獲得Account.field1 - Account.Field2的值,該怎麼做? - 這是聲明無法在postgres中運行預處理語句/函數
PREPARE get_account (varchar) AS
SELECT * FROM "Accounts" WHERE "AccountKey" = $1 LIMIT 1;
-- Try to run directly
select EXECUTE(get_account("A200"));
--Created a function and used statement.
CREATE OR REPLACE FUNCTION accountbalance(VARCHAR) RETURNS REAL AS $$
DECLARE
AKey ALIAS FOR $1;
balance REAL;
account RECORD;
BEGIN
account := EXECUTE(get_account("A200"));
--Tried these too
--account := EXECUTE get_account('A200');
--account := EXECUTE get_account("A200");
--I need to get account data here, process, How to get data to a declared variable, how user specific column, May be something like Accounts."Total"..
--I tried to run direct query here and get data to account, but no success so tried prepared statement.
--I will be doing complex calculations here, trying to return a column for test , not sure is it correct?
RETURN account.Actual;
END;
$$ LANGUAGE plpgsql;
--Used function in sql
Select accountbalance('A200');
在這兩種情況下
收到錯誤這樣的。
錯誤:列「A200」不存在 LINE 1:select EXECUTE(get_account(「A200」)); ^
********** **********錯誤
錯誤:列 「A200」 不存在 SQL狀態:42703 字符:28
雙引號用於關係,而不是值 –
當你選擇EXECUTE(get_account(「A200」))時,你不執行預備語句;' - 你執行你的函數 –
我嘗試了所有選項,選擇EXECUTE(get_account ('A200')),然後選擇EXECUTE(get_account(A200)); –