what am I doing wrong here ? ``` create or replace...
# sql
d
what am I doing wrong here ?
Copy code
create or replace function latestOilFee()
return array
IS
Begin
select * from oil_tracker order by ts desc fetch first 1 row only;
End;
Error: syntax error at or near "return"
s
An array is a container for other data types, and postgres doesn't know what you expect the result to be. This should work:
Copy code
sql
CREATE OR REPLACE FUNCTION latestOilFee()
RETURNS SETOF oil_tracker
AS $BODY$
BEGIN
    RETURN QUERY
    SELECT *
    FROM oil_tracker
    ORDER BY ts DESC
    LIMIT 1;
END;
$BODY$ LANGUAGE plpgsql
d
interesting I thought array is also a data type
Thank you so much, much appreciated 🙏