I have a postgres plpgsql
function that returns a table of cars:
CREATE OR REPLACE FUNCTION getCarsList()
RETURNS TABLE (
model varchar,
engine varchar,
manufacturer varchar
) AS $$
BEGIN
RETURN QUERY SELECT * FROM cars;
END;
$$ LANGUAGE plpgsql;
Now, I want to retrieve all table columns from the function and print them using Java. I've tried to write the following code:
result = statement.executeQuery("SELECT getCarsList()");
while (result.next()) {
System.out.println(result.getString(("model")));
System.out.println(result.getString(("engine")));
System.out.println(result.getString(("manufacturer")));
}
But got the following SQLSyntaxErrorException
:
Message: The column name model was not found in this ResultSet.
SQLState: 42703
ErrorCode: 0
So, since I don't really understand what is causing the message, is there a way to do what I want?