Search code examples
db2ibm-midrange

Run a SQL query on a DB2 file with a dot "." in the name?


I have a DB2 file with a name like "my.test". The DB2 filename contains a dot '.'

If I try and run the following query via strsql:

select * from my.test

I receive the following error:

Token . was not valid. Valid tokens: FOR USE SKIP WAIT WITH FETCH ORDER UNION EXCEPT OPTIMIZE.

Is there a way around this? I tried surrounding it in quotes but that doesn't help.


Solution

  • Double quotes are the correct way to escape the file name. The file name becomes case sensitive within quotes and must be specified in upper case.

    SELECT * FROM "MY.TEST"
    

    Note that in the IFS naming convention the "." operator is used to reference members within a file but it doesn't work with SQL.

    If you need to access a file named "MY" with a member named "TEST" you would need to create an alias to query against.

    CREATE ALIAS QTEMP/MYTEST FOR MY (TEST)
    SELECT * FROM QTEMP/MYTEST