Skip to content

"Invalid parameter 1: Parameter index is out of range" when SQL contains comments (-- comment style) #39

@pybokeh

Description

@pybokeh

Hello!
After I've upgraded to version 0.1.8, now my ETL job is failing with the traceback below:

Traceback (most recent call last):
  File "C:\Users\<some_user>\apps\python38\envs\prefect_dev\lib\site-packages\pandas\io\sql.py", line 1697, in execute
    cur.execute(*args, **kwargs)
  File "C:\Users\<some_user>\apps\python38\envs\prefect_dev\lib\site-packages\jaydebeapi\__init__.py", line 532, in execute
    self._set_stmt_parms(self._prep, parameters)
  File "C:\Users\<some_user>\apps\python38\envs\prefect_dev\lib\site-packages\jaydebeapi\__init__.py", line 523, in _set_stmt_parms
    prep_stmt.setObject(i + 1, parameters[i])
com.ibm.db2.jcc.am.com.ibm.db2.jcc.am.SqlSyntaxErrorException: com.ibm.db2.jcc.am.SqlSyntaxErrorException: [jcc][10145][10844][4.15.146] Invalid parameter 1: Parameter index is out of range. ERRORCODE=-4461, SQLSTATE=42815

This is a codebase that is at least a few years old and nothing was changed, so I have no idea what the root cause could be. So out of desperation, I just removed the comments from the SQL query, and now it no longer errors. I am not sure if it is due to jinjasql or perhaps jinja2 or the other libraries I'm using. I am just connecting to a mainframe DB2 server using jaydebeapi library (JDBC).

Below is my heavily modified, redacted SQL with the comments roughly in the same location as they are in the original SQL. I am using just the single line comment style (-- my comments):

SELECT DISTINCT
    -- Renaming columns to match query with other query to help facilitate
    -- column to column comparisons between this database and the other database 
    'BLAH' AS SOURCE,
    RTRIM(BLAH.BLAH_BLAH) AS "PLANT-CD",
    BLAH.BLAH_BLAH AS "SUPP-CD",
    BLAH.BLAH_BLAH AS "SUPP-LOC",
    RTRIM(BLAH.PART_NO) AS "PART-NO",
    -- our part # does not have space in the middle
    REPLACE(RTRIM(BLAH.BLAH_BLAH), ' ', '') AS "PART-NO-NOSPACE",
    BLAH.BLAH_BLAH AS "BLAH_BLAH",
    
    -- Create ROW_NUM column to identify duplicate records at the
    -- plant, supplier code, supplier location, container type, and part number level
    row_number() OVER(PARTITION BY RTRIM(BLAH.PLANT_CD), RTRIM(BLAH.BLAH_BLAH), BLAH.BLAH_BLAH, BLAH.BLAH_BLAH, RTRIM(BLAH.BLAH_BLAH)
        ORDER BY BLAH.BLAH_BLAH ASC, BLAH.BLAH_BLAH DESC) AS ROW_NUM

FROM
    {{ plant_code3 | sqlsafe }}32.BLAH AS BLAH_BLAH
    
    -- To obtain supplier location code
    LEFT JOIN {{ plant_code3 | sqlsafe }}32.BLAH AS BLAH_BLAH ON
        AND BLAH.EXPIRE_DT > INT(REPLACE(CHAR(CURRENT DATE - 1 DAY, ISO),'-',''))
        
WHERE
    -- Ensure effective date <= today's date and expire date > today's date
    -- Can alternatively use HEX(CURRENT DATE) to obtain current date in YYYYMMDD format
    BLAH_BLAH.EFCT_DT <= (SELECT VARCHAR_FORMAT(CURRENT TIMESTAMP, 'YYYYMMDD') FROM SYSIBM.SYSDUMMY1)
    PLANT_CD = {{ plant_code }}
FOR READ ONLY WITH UR

OS: Windows 10
Python version: 3.8.10
jinja2 version: 3.0.1
jinjasql version: 0.1.8
jaydebeapi version: 1.2.3
database: IBM DB2 z/OS v10.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions