Catch sql query result in file shell

725 views Asked by At

I'm trying to capture the output of a sql query launched via script.

The script :

#!/bin/bash
sql articledb <<< "select toppapier from table \g \q"

The output:

INGRES TERMINAL MONITOR Copyright 2008 Ingres Corporation
Ingres Linux Version II 9.2.0 (int.lnx/143)NPTL login
Thu Aug 31 16:38:02 2017

continue
* Executing . . .

E_US0836 line 1, Column 'toppapier' not found in any specified table.
    (Thu Aug 31 16:38:02 2017)

Ingres Version II 9.2.0 (int.lnx/143)NPTL logout
Thu Aug 31 16:38:02 2017

I want to redirect the output to a file and ONLY catch the error/result (here: E_US0836 line 1, Column 'toppapier' not found in any specified table.)

How may I achieve this?

1

There are 1 answers

0
G Jones On

The Ingres terminal monitor (sql) has some commands which would help, but I don't think these were available in 9.2.0 which is now quite elderly; it's worth checking your support position on that release.

If you're stuck on 9.2.0 and can't upgrade, I think your best bet would be to redirect output to a file and check that for errors. I usually use: egrep "^E_[A-Z]{2}[0-9A-F]{4}"

An alternative might be to install a separate client of a later version, and use that to reach the existing 9.2.0 databases. This would allow the use of commands within the terminal monitor to control the format of the output - such as \silent, [no]titles, \vdelim, \colformat, and \redir (useful if you want errors and query output sent to different destinations). There's more info on those commands in the online documentation. On docs.actian.com, look for the Ingres Command Reference Guide -> Using Ingres Commands -> sql Command -> Terminal Moitor Command Summary.