0
votes

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

column_name

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?

1

1 Answers

0
votes

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.