Skip to main content
17-Peridot
March 24, 2023
Solved

Dynamic SQL query with PostgreSQL and Thingworx

  • March 24, 2023
  • 1 reply
  • 1340 views

I'm trying to fetch data from PostgreSQL database.

Query,

select 
 entry_timestamp + interval '30 minutes' as offset_timestamp,
 entry_timestamp
from 
 sensor_data

I'm trying to pass 30 minutes from Thingworx input.

select 
 entry_timestamp + interval '<dynamic>' as offset_timestamp,
 entry_timestamp
from 
 sensor_data

How to do that?

Best answer by Velkumar

Hi @Sathishkumar_C 

 

You can try something like this. Just pass the whole '30 minutes' (with a single quote) as input to the service

 

c4.PNG

1 reply

Velkumar19-TanzaniteAnswer
19-Tanzanite
March 24, 2023

Hi @Sathishkumar_C 

 

You can try something like this. Just pass the whole '30 minutes' (with a single quote) as input to the service

 

c4.PNG

17-Peridot
March 24, 2023

Thanks @Velkumar 

 

select 
 entry_timestamp + make_interval(mins => <<offset_interval>>) as offset_timestamp,
 entry_timestamp
from 
 sensor_data

 

Got a expected output with above code. offset_interval (Ex. 30is passing from ThingWorx service.

Below one also working as expected,

select 
 entry_timestamp + <<offset_interval>> as offset_timestamp,
 entry_timestamp
from sensor_data

offset_interval (Ex. interval '30 minutes'is passing from ThingWorx service.