将表计数设置为shell脚本中的变量



我希望从我写的sql中返回"计数"变量中的数字值。不幸的是,我只是收到Ingres错误消息。有什么想法我做错了什么?

请参阅下面的Shell脚本代码:

#!/bin/ksh
###############
count=$(sql db_name -s -N "SELECT COUNT(*) FROM temp_table;")
echo "Table count = $count"

请参阅下面的Ingres错误:

Table count = INGRES TERMINAL MONITOR Copyright 2008 Ingres Corporation 
E_US0022 Either the flag format or one of the flags is incorrect,
    or the parameters are not in proper order.

预期结果:

Table count = 8

尝试以下:

=>|Fri Feb 17|01:51:01|postgres@[STATION]:/var/lib/pgsql> ./test.sh
count ------- 3 (1 row)
=>|Fri Feb 17|01:51:04|postgres@[STATION]:/var/lib/pgsql> cat test.sh
#!/bin/bash
count=$(psql <<EOF
select count(*) from mdn_2 ;
EOF
)
# Prints the result captured from DB
echo $count
=>|Fri Feb 17|01:51:05|postgres@[STATION]:/var/lib/pgsql>

-n不是Ingres终端监视器(SQL命令)的有效标志。您可能想要这样的东西(在bash中):

count=`echo "select count(*) from iitables;g" | sql -S iidbdb`

有关接受标志的更多信息,请参阅文档:http://docs.actian.com/#page/ing_commandref/commandref_body.1.235.htm#

最新更新