levylabpitt / LV-Data

Collection of LabVIEW VIs to read and write lab data.
BSD 3-Clause "New" or "Revised" License
3 stars 1 forks source link

pgsql: time #117

Closed ciozi137 closed 1 month ago

ciozi137 commented 1 month ago
ciozi137 commented 1 month ago

Solution for converting timestamp w/timezone: image

The UTC == T flag probably does not matter since the ISO8601 format will include the timezone (either Z for 'Zulu'/UTC or explicitly include the offset).

We do need the following additional code during the INSERT (and presumably during a SELECT): image

ciozi137 commented 1 month ago

There are several issues here to deal with:

ciozi137 commented 1 month ago

The following code will work for inserting time into hypertables that use either timestamp OR timestamptz (using only Timestamp to UTC8601 UTC DateTime.vi does not work)

image

surprisingly the TIMESTAMP WITH TIMEZONE isn't necessary? image

Ah, that is because it is already in UTC. Probably not a safe assumption and the string should be cast to timestamptz (::timestamptz).

The following is valid for inserting into timestamp or `timestamptz columns:

insert into timestamp_demo (ts, tstz)
values('2024-10-01 12:12:31.420519'::timestamptz, '2024-10-01T16:12:31.420Z'::timestamptz);
ciozi137 commented 1 month ago

Updated code to get datatype of an empty column (pg_typeof()) will only work if the column has data inserted

SELECT data_type
FROM information_schema.columns WHERE table_schema = 'public'
AND table_name = 'timestamp_demo' AND column_name = 'ts';
ciozi137 commented 1 month ago

Get Column Datatype.vi: image

ciozi137 commented 1 month ago

Add Get Table Time datatype.vi for convenience: image