How to fake oracle ROWNUM in postgres?
Here's my function - it relies on rownum - a synthetic column in oracle. Why it wants rownum =1 I have no idea - someone could explain to me what the point of doing something like this is as well as how to work around it and I would be very grateful:
\nCREATE OR REPLACE FUNCTION getAgeReduction(integer, timestamptz) RETURNS numeric AS\n\n' DECLARE\npoId Alias for $1;\nDATEOFBIRTH Alias for $2;\nage integer;\nrows integer;\nminOid integer;\nBEGIN\nage := Age(DATEOFBIRTH);\nSELECT ReductionLifeBenefitPercentage INTO AgeReductionPercentage\nFROM (\nSELECT ReductionLifeBenefitPercentage, ReductionLifeBenefitAge\nFROM( SELECT ReductionLifeBenefitPercentage, ReductionLifeBenefitAge\nFROM GroupLifeReduction\nWHERE planOptionId = poId\nAND ReductionLifeBenefitAge <= age\nORDER BY ReductionLifeBenefitAge DESC) as Sub2\nWHERE ROWNUM = 1\nUNION\nSELECT ReductionLifeBenefitPercentage, ReductionLifeBenefitAge\nFROM( SELECT ReductionLifeBenefitPercentage, ReductionLifeBenefitAge\nFROM GroupLifeReduction\nWHERE planOptionId = poId\nAND ReductionLifeBenefitAge >= age\nORDER BY ReductionLifeBenefitAge ASC) AS Sub1\nWHERE ROWNUM = 1\n) AS Sub3 WHERE ROWNUM = 1;\nIF AgeReductionPercentage is null THEN\nreturn 0;\nELSE\nreturn AgeReductionPercentage/100;\nEND IF;\nEND'\nlanguage 'plpgsql';\n
.....To the future or to the past, to a time when thought is free, when men are different from one another and do not live alone -- to a time when truth exists and what is done cannot be undone:
.....From the age of uniformity, from the age of solitude, from the age of Big Brother, from the age of doublethink -- greetings!
-- George Orwell, 1984
How to fake oracle ROWNUM in postgres
Here's my function - it relies on rownum - a synthetic column in oracle. Why it wants rownum =1 I have no idea - someone could explain to me what the point of doing something like this is as well as how to work around it and I would be very grateful:
CREATE OR REPLACE FUNCTION getAgeReduction(integer, timestamptz) RETURNS numeric AS
' DECLARE
poId Alias for $1;
DATEOFBIRTH Alias for $2;
age integer;
rows integer;
minOid integer;
BEGIN
age := Age(DATEOFBIRTH);
SELECT ReductionLifeBenefitPercentage INTO AgeReductionPercentage
FROM (
SELECT ReductionLifeBenefitPercentage, ReductionLifeBenefitAge
FROM( SELECT ReductionLifeBenefitPercentage, ReductionLifeBenefitAge
FROM GroupLifeReduction
WHERE planOptionId = poId
AND ReductionLifeBenefitAge <= age
ORDER BY ReductionLifeBenefitAge DESC) as Sub2
WHERE ROWNUM = 1
UNION
SELECT ReductionLifeBenefitPercentage, ReductionLifeBenefitAge
FROM( SELECT ReductionLifeBenefitPercentage, ReductionLifeBenefitAge
FROM GroupLifeReduction
WHERE planOptionId = poId
AND ReductionLifeBenefitAge >= age
ORDER BY ReductionLifeBenefitAge ASC) AS Sub1
WHERE ROWNUM = 1
) AS Sub3 WHERE ROWNUM = 1;
IF AgeReductionPercentage is null THEN
return 0;
ELSE
return AgeReductionPercentage/100;
END IF;
END'
language 'plpgsql';
.....To the future or to the past, to a time when thought is free, when men are different from one another and do not live alone -- to a time when truth exists and what is done cannot be undone:
.....From the age of uniformity, from the age of solitude, from the age of Big Brother, from the age of doublethink -- greetings!
-- George Orwell, 1984