Extracting numeric value from output of a uder defined aggregate in netezza using bash script
- by Ankit
I am executing a shell script to execute my user defined aggregate which is taking inputs yavg=nzsql -c 'select avg(x) from Input1' which is giving output like this
AVG ---------- 2.000000 (1 row)
I want to pass only the numeric(double) value which is 2.0000(where xavg is expected) from this to S4(x,y,$xavg,$yavg) where x and y are the whole column from table Input1,
xavg=nzsql -c 'select avg(y) from Input1'
Below is my InputTable.txt which is a text file from which I am popluating my "Input1" table in the shell script.
1 2 3
2 1 2
3 2 1
nzsql -c 'create table Input1(x integer, y integer, v integer)'
nzload -t Input1 -df InputTable.txt
nzsql -c 'select * from Input1
yavg=`nzsql -c 'select avg(x) from Input1'`
xavg=`nzsql -c 'select avg(y) from Input1'
nzsql -c 'select S4(x,y,$xavg,$yavg) from test'
Below is the output :
xavg := AVG ---------- 2.000000 (1 row)
yavg := AVG ---------- 1.666667 (1 row)
and i am passing this value to S4(x,y,$xavg,$yavg) which is a User defined aggregate