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
2
  • 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. Commented Feb 16, 2017 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? Commented Feb 16, 2017 at 17:44

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

2 Comments

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"?
Possible for you to share the screenshot here? I can then check and respond.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.