Icon

DB SQL - H2 Database dynamic Query with datetime

<p>Create a DB Query in KNIME to only give back the latest values after a certain date</p>

URL: Create a DB Query in KNIME to only give back the latest values after a certain date - KNIME Forum (83720) https://forum.knime.com/t/row-filter-on-database-level-to-only-get-incremental-load-of-data/83720/9?u=mlauber71
URL: KNIME, Databases and SQL https://medium.com/p/273e27c9702a

Use a VIEW that selects the latest Timestamp and then use a merge to only keep the latest one. In this case it is the same table but this could be used on different tables

Create a DB Query in KNIME to only give back the latest values after a certain date

https://forum.knime.com/t/row-filter-on-database-level-to-only-get-incremental-load-of-data/83720/9?u=mlauber71

SELECT * FROM "PUBLIC"."sample_table"

WHERE "Zoned Date Time" >= (SELECT MAX("Zoned Date Time") FROM "PUBLIC"."sample_table")

SELECT * FROM "PUBLIC"."sample_table"

WHERE "Zoned Date Time" >=

TIMESTAMP '$${Svar_max_time}$$'

KNIME, Databases and SQL

https://medium.com/p/273e27c9702a

prepare data to have several different dates

CREATE VIEW IF NOT EXISTS "PUBLIC"."v_max_timestamp" AS

SELECT MAX("Zoned Date Time") AS "Max Zoned Date Time"

FROM "PUBLIC"."sample_table"

Create a H2 table "sample_table"

https://hub.knime.com/-/spaces/-/~4-Nz2crmY1OvrH_M/current-state/
Create Dummy Data
Chunk Loop Start
DB Reader
Loop End
DB Query Reader
var_max_time
Column Renamer
var_max_time
Table Row to Variable
join bythe maximum timestamp
DB Joiner
"PUBLIC"."v_max_timestamp"
DB SQL Executor
sample.table
Table Writer
"PUBLIC"."v_max_timestamp"
DB Table Selector
sample_table
DB Table Deleter
Read from the H2 table "sample_table"just the records with the latest "Zoned Date Time"
DB Query Reader
select data greater then the day beforethe MAX
DB Query Reader
Duration(convert it back just for fun)
String to Duration
"PUBLIC"."sample_table"
DB Table Selector
transfer to table
DB Writer
Column Filter
subtract_d
Variable Expression
Zoned Date Time
Date Shifter
create tbalesample_table
DB Table Creator
subtract_d
Constant Value Column Appender
DB Query Reader
Column Filter
in memory
H2 Connector

Nodes

Extensions

Links