Skip to content
Advertisement

I want to get result of a query for every day(that particular day) when the new data arrive

I am writing a python script to get reports of data every day. For example, data is coming continuously and I want to get the report just for the data that came that day. So the report will be generated every day and I want my query to be executed for that day only using a timestamp column in the data.

timestamp column-

DOR                 ROW
2018-12-20 02:08:12 1
2018-12-20 02:08:12 2
2018-12-20 02:08:12 3
2018-12-20 02:08:12 4
2018-12-20 02:08:12 5
2018-12-20 02:08:12 6
2018-12-20 02:08:12 7
2018-12-20 02:08:12 8
2018-12-20 02:08:12 9
2018-12-20 02:08:12 10
2018-12-20 02:08:12 11
2018-12-20 02:08:12 12
2018-12-20 02:08:12 13
2018-12-20 02:08:48 14
2018-12-20 02:08:48 15
2018-12-20 02:08:48 16
2018-12-20 02:08:48 17
2018-12-20 02:08:48 18
2018-12-20 02:08:48 19

The data is continuously arriving and the query should give results for that day only.

For both Oracle and Postgresql DBMS.

Advertisement

Answer

In either Oracle or Postgres, you could use:

where to_char(timestamp, 'YYYY-MM-DD') = to_char(current_timestamp, 'YYYY-MM-DD')

This is not particularly efficient, because it cannot use an index on timestamp.

That said, the following are database-specific. For Oracle:

where timestamp >= trunc(sysdate) and timestamp < trunc(sysdate) + interval '1' day

For Postgres:

where timestamp >= current_date and timestamp < current_date + interval '1 day'

Both of these can make use of an index on timestamp.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement