How to get a row in a temp variable and process/use its fields?? See the begin section, I need to get account info, do some calculations, like I need to get value of Account.field1 - Account.Field2 in accountbalance method , how to do that?? --this is statement
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');
in both cases receive error like this.
ERROR: column "A200" does not exist LINE 1: select EXECUTE(get_account("A200")); ^
********** Error **********
ERROR: column "A200" does not exist SQL state: 42703 Character: 28
select EXECUTE(get_account("A200"));- you execute your functionexecute get_account ('a200');