TCP
TCP

Reputation: 33

Setting table count to variable in shell script..?

I'm looking to return a numeric value within the "count" variable from my SQL I wrote. Unfortunately I am just getting an Ingres error message. Any ideas what I am doing wrong?

See shell script code below:

#!/bin/ksh
###############

count=$(sql db_name -s -N "SELECT COUNT(*) FROM temp_table;")

echo "Table count = $count"

See Ingres error below:

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.

Expected outcome:

Table count = 8

Upvotes: 1

Views: 3731

Answers (2)

G Jones
G Jones

Reputation: 367

-N isn't a valid flag for the Ingres terminal monitor (sql command). You probaby want something like this (in bash):

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

For more info on the flags accepted, see the documentation: http://docs.actian.com/#page/Ing_CommandRef%2FCommandRef_Body.1.235.htm%23

Upvotes: 1

User9102d82
User9102d82

Reputation: 1190

Try this:

=>|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>

Upvotes: 1

Related Questions