Caetano Traina Junior schrieb am 18.07.2021 um 15:19:>
Em sáb., 17 de jul. de 2021 às 05:33, Thomas Kellerer <shammat@xxxxxxx <mailto:shammat@xxxxxxx>> escreveu: And before you ask: it's not really possible to make this dynamic, so that the number of columns "automagically" increases when you have more fruits. One fundamental restriction of the SQL language is that the number and types of all columns must be known to the database when the query is parsed. It can't change the columns as a result of the query itself.
Nonetheless, it is always possible to write a dynamic SQL (and best yet, inside a plpgsql function) to "automagically handle more fruits..."
Even if you create a function that uses dynamic SQL, you still have to specify each output column "manually" when calling the function. So that doesn't really buy you anything.