sql - Postgresql current_time stamp in Asia/kolkata changes when I change system date time -


i have postgresql installed on system in india timezone comes in asia/kolkata.

what need current_timestamp tried following queries:

select now()  select current_timestamp @ time zone 'asia/kolkata' 

which gives me time-stamp correctly.

but if change system date or time , use query giving me result changed date time. wrong.

how can query or change neccessary conf make such way time stamp should comes correctly asia/kolkata , should in-depended of system date time.

postgresql version : 9.3

you can't using postgresql alone, now()and current_timestamp depend on system date. basically, running on server based on system date.

you have make sure system date accurate (with ntp sync) or use external service.

here way request external time using sql only, it's far being effective or extremely accurate:

create or replace function external_now() returns timestamp time zone $$     declare last_external_now timestamp time zone := null;     begin         create temporary table external_now (             text         );          copy external_now         program 'curl -s http://www.timeapi.org/utc/now -w "\n"';          select cast(now timestamp time zone)         external_now         order desc         limit 1         last_external_now;          drop table external_now;          return last_external_now;     end; $$ language plpgsql      volatile      -- allow non superuser call function      security definer     cost 100000 ; 

you have create function superuser can run anyone:

test=> select external_now();       external_now ------------------------  2016-04-26 07:00:17+00 (1 row)  test=> select external_now() @ time zone 'asia/kolkata';       timezone ---------------------  2016-04-26 12:30:21 (1 row) 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -