Reputation: 105
I have a Table named TEST with column name col1, col2, col3,col4.......... So, from information_schema.columns i will get details about this table object.
Now, i want to build a select query from TEST table by supplying colum name from information_schema.columns. like this, select column_name from information_schema.columns where table_name = 'TEST'.This will return
col1 col2 col3
i want to use this output in select query from TEST. Like this select col1, col2,col3,col4 from TEST.
Is this possible by single query?
Upvotes: 0
Views: 380
Reputation: 247930
You will have to compose an SQL string and execute that.
You can either do that with your client application or in a PostgreSQL function.
You must take special care to escape all string values using the format
function or quote_ident
and quote_literal
to avoid problems from SQL injection.
Upvotes: 0