1

I need to create a single dynamic select query for different tables in Netezza.

I get the list of columns for any table by using following query:

select * from _V_SYS_COLUMNS where TABLE_NAME='Table Name'

But I need to append all the values of Column ‘Column_Name’ separated by comma and store it into a variable:

var= col1,col2,....

And then I will pass this ‘var’ in select query to run it for different tables.

Note: I cannot use Select * because all the columns are not required.

1 Answers1

0
$ COLUMNS=`nzsql -A -t -c "select column_name from _v_sys_columns where table_name = 'NZ_CHECK_DISK_SCAN_SPEEDS';"  -R "," | sed -e "s/,$//"`

$ echo "$COLUMNS"
THE_DATASLICE,THE_EXTENT,THE_PAGE,THE_ROW,FILLER1,FILLER2

Mark F
  • 271
  • 1
  • 1
  • Hi Mark, Thanks for your response! I am new to Netezza and my Netezza is installed on Windows machine. I am running the queries on Aginity Workbench. I think your suggestions can be implemented on Unix or Netezza commandline. Could you please suggest something which I can implement on Windows. – Shikhar Dwivedi Mar 04 '21 at 16:37
  • While this piece of code may provide a solution to the question, it's better to add context as to why/how it works. This can help future users refer to and eventually apply this knowledge to their own code. You are also likely to have positive feedback/upvotes from users, when the code is explained. – Amit Verma Mar 04 '21 at 18:04
  • I just added a bit of context on Mark’s behalf :) – Lars G Olsen Mar 07 '21 at 07:52