'In a Postgres function, how to return the result of a query that is stored in a table?
Initially let me explain the whole situation. The database is Postgres 13.
I need a "dynamic selection"
In the first place...
The tables I work with have many columns (approximately 200 columns). My goal is to create a function that takes the inputs: database schema, table name and the column range I want to use in "dynamic selection". For example, let's say I have a table called "customers" in a "public" schema and I want to list the contents of ordinal number columns between 20 and 50. I would simply call the function and the dynamic result would appear on the screen (something like select * from function(customers, public, 20, 50), internally the function would assemble a query something like this:
select column20, column21, column22, column23... column50
from public.customers;
So, internally the function executes this query "select column20, column21, column23...column50 from public.clientes" and will return the result of it on the screen.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
