Home
Designing Analytics Reports
Naming parameters in BIRT and testing sql
Migrateduser
<p>I would like to use named parameters with Postgres jdbc queries in BIRT instead of sequentially numbered queries.</p>
<p> </p>
<p>Reasons:</p>
<p>1. Less chance of mixing the parameters up</p>
<p>2. Easier to test and debug parts of the the query in another tool e.g. SQL Workbench.</p>
<p> </p>
<p>With BIRT using the Oracle driver ojdbc14.jar allowed the use of named queries, such as this. Note the same variable is used once, and variable1 only has to be added once to the dataset parameter list.</p>
<p> </p>
<p>select col1, col2 from tablex</p>
<p>where filtercol >= :variable1</p>
<p> and filtercol <= :variable1 + 10</p>
<p> </p>
<p>But, with BIRT using the Postgres postgresql-9.0-801.jdbc3.jar jdbc drivers, this doesn't work.</p>
<p>With Postgres, you have to do the following.</p>
<p> </p>
<p>select col1, col2 from tablex</p>
<p>where filtercol >= ?::integer</p>
<p> and filtercol <= ? + 10</p>
<p> </p>
<p>If you want to use a single parameter more than once in the query, you have to do this:</p>
<p>select col1, col2 from tablex</p>
<p>where filtercol >= ?::integer</p>
<p> and filtercol <= $1 + 10</p>
<p> </p>
<p>This query does not work in other tools, such as SQL Workbench. If I want to test this or far more complex queries, it's not a matter of copying the BIRT query across. All variables have to be changed to the following.</p>
<p>select col1, col2 from tablex</p>
<p>where filtercol >= $[variable1]::integer</p>
<p> and filtercol <= $[variable1]::integer + 10</p>
<p> </p>
<p>To move the working query to BIRT, the parameter format has to be changed once more, with the possibility of more errors. This is a nuisance if the query is complex.</p>
<p> </p>
<p>With BIRT and Oracle, the query could be used as is.</p>
<p> </p>
<p>Is there a syntax I can use that will work on Postgres with both BIRT and SQL Workbench, or perhaps a JDBC driver you recommend?</p>
<p> </p>
<p>I've tried other SQL tools, e.g. SQLMaestro, and it uses yet another variable syntax.</p>
<p> </p>
<p>your help will be appreciated</p>
<p>Brian</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
Find more posts tagged with
Comments
There are no comments yet