I am attempting to run the following command in KornShell (ksh):
set -A INDEXES `db2 "describe indexes for table ${TABSCHEMA}.${TABNAME} show detail" | awk '{print $1"."$2}'`
What I am attempting to achieve is place a list of the indexes over a particular table into an array which I can later iterate through.
The problem is, when I run the above command the contents of the array starts with the error message of ‘SQL1024N’ (which is telling me that the database connection does not exist).
However, if I remove the awk at the end of the statement as so:
set -A INDEXES `db2 "describe indexes for table ${TABSCHEMA}.${TABNAME} show detail"`
it works just fine (well, to the extent it is returning data. Obviously without the awk I am not capturing the correct data).
Does anyone know why the awk is having this affect?
I appreciate there is more than one way to get this data, but it baffles me as to why this is happening.
Thanks in advance.
In this case, when the DB2 CLP says that it’s not connected to the database, it’s because the shell has opened up a sub-process that requires its own dedicated db2bp backend process, which cannot access the connection opened by the original shell process. It’s not that something is becoming disconnected, it’s that a newly created shell process (and its accompanying db2bp process) are being created but aren’t being told to connect to a database.
One way to remedy this is to explicitly connect (or re-connect) to the database when you know you’re in one of those situations.
I realize that this question is more about scripting and awk with DB2 than about the system catalog, or else I would have recommended some straightforward catalog queries to produce the same result.