The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.
I am running a bit of dynamic SQL in a stored procedure to cycle through tables in a database and get rowcounts. After the execute immediate, I am capturing SQLSTATE. For the most part, SQLSTATE is 00000, however in a few cases, it is 54001. The query to get the count appears to finish OK... and i run it manually to verify that it finishes... just not sure why it is throwing SQLSTATE of 54001. I cannot seem to find the definition of this state online... below is a piece of the code so you can see where i am capturing SQLSTATE.
TRIM(TableName) ASTabNameFROMdbc.TablesvWHEREtrim(DatabaseName) ='DLAB_CIO'ANDTableKindin ('T','V')
DOSETSqlTxt='INSERT INTO DLAB_CIO.NSC_RowCounts '||'SELECT '||''''||cur.DBName||''''||','||''''||cur.TabName||''''||','||'CAST(COUNT(*) AS BIGINT)'||','||'CURRENT_TIMESTAMP(2) '||'FROM '||cur.DBName||'.'||cur.TabName||';';EXECUTEIMMEDIATEsqlTxt;ifSQLSTATE<>'00000'thenINSERTintoDLAB_CIO.AAA_TB_LOGvalues ('DB: '||cur.DBName||'; '||'TBL: '||cur.TABName||'--'||SQLSTATE);end if;
If you check the appendix in the SQL Reference: SQL Stored Procedures and Embedded SQL manual, you will find that SQLSTATE 54001 is mapped to a variety of database ErrorCode values that relate to exceeding some sort of internal database limit - and a few of those (such as 3705) are just warnings.
You could define an error handler and use GET DIAGNOSTICS EXCEPTION variable_name = MESSAGE_TEXT; to obtain more detail.