Question & Answer
Question
How do I pass variables using nzsql
Answer
Several ways to pass variables to nzsql ....
1) Using shell script and then passing variable as unix shell variable.
shellscript.sh <TABLENAME>
in shellscript.sh....
nzsql -c "select * from $1"
2) Setting variable within nzsql.
TESTDB.ADMIN(ADMIN)=> \set tvar '\'BLAH\''
TESTDB.ADMIN(ADMIN)=> select :tvar col_alias;
COL_ALIAS
-----------
BLAH
(1 row)
3) Passing variable at nzsql.
[nz@nz80409-h2 ~]$ nzsql -v "tbl=backup_tmp"
TESTDB.ADMIN(ADMIN)=> select * from :tbl;
DBNAME | STARTTIME | LASTUPDATE
--------+---------------------+---------------------
| 2014-12-23 02:43:16 | 2014-12-23 02:43:24
Was this topic helpful?
Document Information
Modified date:
17 October 2019
UID
swg21984692