on 10-31-2019 12:26 AM
I'm using HANA hdbsql to execute a SQL script containing many SQL statements. I want it to immediately stop processing the input file and exit with an error code as soon as any statement gets an error. Is there a way to do this? In Oracle's sqlplus, this functionality is enabled with "whenever sqlerror exit sql.sqlcode". I haven't found anything like this in the hdbsql documentation. Not having this capability makes it very difficult to create effective scripts. You have to be able to detect when something doesn't work and stop.
That is possible with hdbsql for HANA 2 (my version is 2.3.119) by using the -E <error code> command line parameter.
For example with a script like this:
> cat test.sql
select '1', current_timestamp from dummy;
insert into test values (1, 'YYY');
select '2', current_timestamp from dummy;
and a table that has a primary key constraint on the first value, I should get an error message when I run the script multiple times.
> ./hdbsql -U HXEDEV -E 5 -I test.sql
'1',CURRENT_TIMESTAMP
"1","2019-10-31 14:20:51.844000000"
* 301: unique constraint violated: Table(TEST) with error: unique constraint violation on pos=0 for table HXE::SYSTEM:TEST$delta_1$en, key: AAA=1 already exists as udiv=1 SQLSTATE: 23000
>
The script has stopped now and hdbsql exited. The error code should be 5 (as we specified -E 5):
> echo $?
5
So, "it works on my machine!" 😉
Cheers,
Lars
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aha! "-E <exit code>" Thank you, Lars.
The -E option is NOT documented in the SAP HANA Administration Guide for SAP HANA Platform (Chapter 14 - SAP HANA HDBSQL Reference) which is where I looked. It does show up in the usage text if you type "hdbsql -?" so at least it is there.
Note to SAP: You need to update the documentation!
Hello,
I am afraid that currently we don't the option to cancel them.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.