The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
Query inputs using 'Set Macros'
I have a query which requires more than one input parameters. As an example
Select count(*) from TestTable where date > '2012/10/05' and date < '2012/10/10'
I would like to pass the date parameter as variable . So my query will look like
Select count(*) from TestTable where date > ? and date < ?
How do I pass 2 variables to the 'Read Database Operator' ? I tried usibg 'Set Macros' and defined 'dt1' and 'dt2' and used them in 'Read Database' with 'prepare statement' and adding VARCHAR {%dt1} and {%dt2} to the Edit Enumeration.
I get the error
ERROR: invalid input syntax for type date: "dt1"
Is there different way to pass more than one variables to sql statement ? It works fine if I have one variable . E.g
Select Count(*) from TestTable where date = ?
And define input variable with 'Set Macro'.
Select count(*) from TestTable where date > '2012/10/05' and date < '2012/10/10'
I would like to pass the date parameter as variable . So my query will look like
Select count(*) from TestTable where date > ? and date < ?
How do I pass 2 variables to the 'Read Database Operator' ? I tried usibg 'Set Macros' and defined 'dt1' and 'dt2' and used them in 'Read Database' with 'prepare statement' and adding VARCHAR {%dt1} and {%dt2} to the Edit Enumeration.
I get the error
ERROR: invalid input syntax for type date: "dt1"
Is there different way to pass more than one variables to sql statement ? It works fine if I have one variable . E.g
Select Count(*) from TestTable where date = ?
And define input variable with 'Set Macro'.
0
Answers
Thanks.
Marcin
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.2.008">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.2.008" expanded="true" name="Process">
<process expanded="true" height="670" width="727">
<operator activated="true" class="read_database" compatibility="5.2.008" expanded="true" height="60" name="Read Database" width="90" x="179" y="30">
<parameter key="connection" value="Vertica"/>
<parameter key="query" value="( Select timestamp from TestTable where DATE(TO_TIMESTAMP( timestamp) ) = cast ( ? as date) ) UNION ALL ( Select timestamp from TestTable where DATE(TO_TIMESTAMP( timestamp) ) = cast ( ? as date));"/>
<parameter key="table_name" value="dimlead"/>
<parameter key="prepare_statement" value="true"/>
<enumeration key="parameters">
<parameter key="parameter" value="VARCHAR.%{dt1}"/>
<parameter key="parameter" value="VARCHAR.%{dt2}"/>
</enumeration>
</operator>
<operator activated="true" class="set_macros" compatibility="5.2.008" expanded="true" height="76" name="Set Macros" width="90" x="45" y="120">
<list key="macros">
<parameter key="dt1" value="2012/06/17"/>
<parameter key="dt2" value="2012/06/18"/>
</list>
</operator>
<connect from_port="input 1" to_op="Set Macros" to_port="through 1"/>
<connect from_op="Read Database" from_port="output" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="source_input 2" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>