1

I'm currently using bash on CentOS. DB2 is installed and db2 is on my path.

I have a few lines in a script which are supposed to update my db2 database, but they aren't working. As a minimal reproduction, I can do the exact same thing right in the bash command line and get the same error. Here's that reproduction:

$ db2 connect to PLT02345 user uni using uni; db2 update USM_USER set STATUS = 1 where NAME = 'asm_admin'

I expect this to set STATUS to 1 for everything in PLT02345.USM_USER where the NAME is currently asm_admin.

Instead, I get an error about "ASM_ADMIN" not being valid in the context where it's used. Here's the full output:

  Database Connection Information

Database server        = DB2/LINUXX8664 10.1.2
SQL authorization ID   = UNI
Local database alias   = PLT02345

DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0206N  "ASM_ADMIN" is not valid in the context where it is used.
SQLSTATE=42703

I'm confused - what about this makes it not valid? Is bash somehow mutilating the command and not passing everything as it should to db2?

1 Answer 1

2

If you're running this from the command line, Bash will drop the 's off 'asm_admin' because it simply assumes you're passing a string. The end result is the SQL becoming WHERE name = asm_admin which is invalid.

To correct this, you need to quote your whole command:

db2 "update USM_USER set STATUS = 1 where NAME = 'asm_admin'"
Sign up to request clarification or add additional context in comments.

2 Comments

Full disclosure: I'm unfamiliar with db2 itself, but does the connect persist across multiple db2 calls? That may also require fixing.
@mr-llama Yes, the DB2 command line processor is built so that a connection does persist across calls.

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.