一時変数で行を取得し、そのフィールドを処理/使用する方法はありますか? 私はaccount.field1 - Account.Field2のaccountbalanceメソッドの値を取得する必要があるように、開始セクションを参照して、私は、アカウント情報を取得する必要がありますいくつかの計算を行うには、それを行う方法?? - これはステートメントですポストグルでプリペアドステートメント/関数を実行できません
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」が存在しません 行1:EXECUTE(get_account( "A200"))を選択します。 ^
********** **********エラー
ERROR:コラム "A200" SQL状態は存在しません:42703 文字:28
二重引用符は値ではなく、値ではありません –
EXECUTE(get_account( "A200"));を選択したときにプリペアドステートメントを実行しません - 関数を実行します –
すべてのオプションを試しましたが、EXECUTE(get_account ( 'A200'))を選択し、EXECUTE(get_account(A200))を選択します。 –