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
SQL Query and date_now()
Hi folks,
Following problem: There is a mysql table with a Timestamp column. I want to retrieve all entries of the current day. I was quite optimistic that the following operator would do the trick:
Anyone got an idea?
Cheers, Mike.
Following problem: There is a mysql table with a Timestamp column. I want to retrieve all entries of the current day. I was quite optimistic that the following operator would do the trick:
Actually it works fine if I use a static value in the macro definition of %{today}:
<operator activated="true" class="read_database" compatibility="5.3.015" expanded="true" height="60" name="DB Import" width="90" x="45" y="30">
<parameter key="connection" value="myDBname"/>
<parameter key="query" value="SELECT `ID`,`Timestamp` FROM `myTablename` Where`Timestamp` >= ?"/>
<parameter key="prepare_statement" value="true"/>
<enumeration key="parameters">
<parameter key="parameter" value="VARCHAR.%{today}"/>
</enumeration>
</operator>
But it fails when I try to dynamically calculate the current date e.g. as follows:
<macros>
<macro>
<key>today</key>
<value>2015-01-13</value>
</macro>
</macros>
As a result I get all entries of the table instead.
<macros>
<macro>
<key>today</key>
<value>date_str_custom(date_now(),"yyyy-MM-dd")</value>
</macro>
</macros>
Anyone got an idea?
Cheers, Mike.
0
Answers
you cannot use expressions in macros directly. Instead you have to add a "Generate Macro" operator. Example process which logs the current date macro to the console: Regards,
Marco
So if there is a datatable, with very many timestamped entries, and I want to query the data for a specific day, which can be chosen dynamically, what would be the best way to do so? I'm a bit reluctant to load the whole table.
Cheers, Mike.
just as you did in your original post, use the macro you define somewhere before executing the "Read Database". You can set the macro with any of the macro operators. As long as it is set before the actual Database operator, you should be fine.
Regards,
Marco