1

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
TCP
  • 33
  • 2
  • 8
  • If you are using the Korn shell, use the `ksh` tag, not the `bash` tag. Regardless, this isn't a shell issue; there's a problem with your SQL command. – chepner Feb 16 '17 at 17:41
  • 1
    Have you tried executing `sql db_name -s -N "SELECT COUNT(*) FROM temp_table;"` to see what the output is outside your script? – Fred Feb 16 '17 at 17:44

2 Answers2

1

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>
User9102d82
  • 1,172
  • 9
  • 19
  • Result is now: "INGRES TERMINAL MONITOR Copyright 2008 Ingres Corporation Ingres SPARC SOLARIS Version II 9.2.1 login Thu Apr 20 11:30:40 2017 continue Executing . . . +-------------+ |col1 | +-------------+ | 8| +-------------+ (1 row) Your SQL statement(s) have been committed. Ingres Version II 9.2.1 logout Thu Apr 20 11:30:40 2017" Any idea's how I can just return "8"? – TCP Apr 20 '17 at 10:33
  • Possible for you to share the screenshot here? I can then check and respond. – User9102d82 Apr 21 '17 at 20:01
1

-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

G Jones
  • 357
  • 1
  • 6