How to List All the Column Names in Netezza

How to figure out the column names programmatically using Netezza SQL, where the column values matches a preset value

Basically you want to transpose data .
These kind of questions were already answered in SO.

Transpose rows to columns based on ID column.

Netezza aggregation issue (pivot)

Hope this helps! If you want more help please reply.

How to list similar column names with select statement?

You'll have to use dynamic nzplsql in a stored procedure. Stored procedures don't easily return tables, though, but you can have it easily output a select statement that builds from _v_relation_column via a cursor. Capture that in bash and feed it to nzsql to select from a table. Either that or you can just return a reftable.

/* Stored procedure header. */
declare sql varchar;
declare col record;
begin_proc
sql := 'select ';
for col in select * from _v_relation_column where name = 'TABLE_NAME' loop
if col.attname like 'year%'
sql := sql || attname || ',';
end if;
sql := substring(sql,1,length(sql)-1); --To strip the last comma. Could probably be more elegant.
sql := sql || ' from table_name;';
raise notice '%',sql;
end_proc;
/* Stored procedure footer. */


Related Topics



Leave a reply



Submit