I have a stored procedure where I declare three variables as records and initialize them later as below:
CREATE OR REPLACE FUNCTION calculateUnitPrice()
RETURNS VOID AS
$$
DECLARE
amenities RECORD;
paramValues RECORD;
logsumAccessebility RECORD;
propertyType integer;
unitPrice float;
freehold integer;
tazId bigint;
unit RECORD;
BEGIN
FOR unit IN (SELECT * from main2012.fm_unit_res)
LOOP
amenities := getAmenitiesById(unit.sla_address_id);
tazId := toBigint(amenities.taz_id);
logsumAccessebility := getLogsumByTazId(tazId);
propertyType := getPropertyTypeFromUnitType(unit.unit_type);
paramValues := getParamValuesByPropertyType(propertyType);
freehold := 0;
unitPrice := paramValues.intercept + (paramValues.floor_area * ln(unit.floor_area)) + (paramValues.freehold * freehold) + (paramValues.logsum_accessebility * logsumAccessebility.accessibility);
UPDATE main2012.fm_unit_res SET rent = unitPrice WHERE fm_unit_id = unit.fm_unit_id;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
But when I run the function I am getting an error like this:
ERROR: record "paramvalues" is not assigned yet
SQL state: 55000
Detail: The tuple structure of a not-yet-assigned record is indeterminate.
Context: PL/pgSQL function calculateunitprice() line 20 at assignment
Please give me your ideas. Am I doing anything wrong here (syntax) or is there a limit in the number of records I can initialize within a stored procedure?
hparamValues :=instead ofparamValues :=? :)raise info '%',getPropertyTypeFromUnitType(unit.unit_type);raise info '%',getPropertyTypeFromUnitType(unit.unit_type);before declaringparamValues, then run function and tell the last value of raised info before error?..