HSQLDB - ON UPDATE CURRENT_TIMESTAMP with TIMESTAMP column - hsqldb

With this table definition:
CREATE TABLE T1 (C1 TIMESTAMP DEFAULT NOW() ON UPDATE CURRENT_TIMESTAMP NOT
NULL);
when a row is updated C1 is set to the current UTC timestamp.
This is what I want however I was wondering if this is also the intended behavior of HSQLDB since CURRENT_TIMESTAMP returns a value of TIMESTAMP WITH TIME ZONE type.

HSQLDB implements the ISO SQL:2016 Standard. The LOCALTIMESTAMP and CURRENT_TIMESTAMP are Standard functions and return TIMESTAMP values WITHOUT or WITH TIME ZONE respectively. The Standard mandates silent two-way conversion between TIMESTAMP values with or without time zone. Therefore the value returned from CURRENT_TIMEZONE is converted to a value without time zone. This is done by discarding the time zone information.

Related

Presto: Publish a table with timezone altered to the correct zone

I am trying to change the timezone of a timestamp in presto, however, as I convert the type of column back to timestamp, the timezone correction is reverted. I need to convert it to timestamp/bigint/string to be able to store the data in a schema as the schema does not store the column type timestamp-timezone. I have tried
SELECT FROM_UNIXTIME(CAST(to_unixtime(CAST('2012-10-31 01:00' AS timestamp) AT TIME ZONE 'US/Pacific') * 1000 AS bigint)/1000);
PostgreSQL => ALTER TABLE without timezone -> with timezone, using select for TZ
Alter timezone constraint PostgreSQL
Can you use a column for the timezone parameter of AT TIME ZONE in Presto / Athena?
How do I convert a string which is actually a date with timezone to a timestamp in Presto?
But have not been able to solve the issue. Is there a way I can store the timezone appended date column in the table without it being reverted?
Thank you!
SELECT CAST(SUBSTR(CAST((FROM_UNIXTIME(CAST(1578514469000 AS BIGINT)/1000) AT TIME ZONE 'US/Pacific') AS varchar), 1, 23) AS timestamp)

How to convert time without time zone to timestamp without time zone?

I need to convert couple of columns in one table in PSQL and I really dont want to drop the table to fix this (thats my last resort). Is there a way to do this, because when I write:
ALTER TABLE table ALTER TABLE column type TIMESTAMP without time zone using column::TIMESTAMP without time zone;
it doesnt work, says:
ERROR:cannot cast type time without time zone to timestamp without time zone.
P.S. If its possible, I would like to avoid dropping columns because I already use indexes of those columns.
If you want the date part to be today:
alter table the_table
alter column the_column type timestamp without time zone
using current_date + the_column
Postgresql will not directly allow to convert time without zone to timestamp without time zone.
You just need to convert first into time without time zone to character varying then change to character varying to timestamp without time zone
You can refer the following query
Changing to character varying:
ALTER TABLE table_name
ALTER COLUMN colum_name TYPE character varying
USING column_name::character varying
Now to change to Timestamp without time zone:
ALTER TABLE table_name
ALTER COLUMN colum_name TYPE Timestamp without time zone
USING column_name::Timestamp without time zone
Now you will be able update successfully.

Insert Timestamp into Varchar2 column in Oracle Database

I am working with an application that interfaces with an Oracle 11g database. I need to insert a timestamp in the YYYYMMDDhhmmss format, into a Varchar2 column.
My SQL update query is:
update CODELIST_XREF_ITEM set RECEIVER_ITEM=TIMESTAMP where LIST_NAME='BUSINESS_PROCESS';
The TIMESTAMP variable is where it need to be inserted. I have tried setting the TIMESTAMP variable to CURRENT_TIMESTAMP, however I am not able to format that.
Any suggestions?
Thanks in advance for all your help!
If you want to insert the character representation of a timestamp (it actually appears that you want the character representation of an Oracle date since you don't want fractional seconds or a time zone), you'd use the to_char function.
to_char( sysdate, 'YYYYMMDDHH24MISS' )
So your UPDATE statement would be
update CODELIST_XREF_ITEM
set RECEIVER_ITEM=to_char( sysdate, 'YYYYMMDDHH24MISS' )
where LIST_NAME='BUSINESS_PROCESS';
If you wanted to store fractional seconds or a time zone or do something else that required a timestamp, you'd use the same to_char function just with a different format mask.

Rowtype and type supported in sqldeveloper.ink

Are % Rowtype and %type not supported by sqldeveloper.ink ?
To clarify: SQL Developer is just a client for the Oracle database, so you're looking for a function in the Oracle database.
You need to decide:
whether you want to get the value as a DATE (which is actually a datetime) or as a TIMESTAMP (which has higher precision (fractions of seconds))
whether you want it for the timezone of the session (which usually equals that of the client) or the server
Functions
SYSDATE (date, timezone of server)
SYSTIMESTAMP (timestamp, timezone of server)
CURRENT_DATE (date, timezone of current session)
CURRENT_TIMESTAMP (timestamp, timezone of current session)
Example query:
select
sysdate,
systimestamp,
current_date,
current_timestamp
from dual
Further reading
Oracle blog entry about the difference between SYSDATE and CURRENT_DATE
Oracle documentation of SYSDATE
Oracle documentation of CURRENT_DATE
SYSDATE();
Returns the current datetime.

Change column type from timestamp WITHOUT time zone to timestamp WITH time zone

I found this ALTER COLUMN statement in the PostgreSQL 9.3 ALTER TABLE manual page:
ALTER TABLE audits
ALTER COLUMN created_at SET DATA TYPE timestamp with time zone
USING
timestamp with time zone 'epoch' + created_at * interval '1 second';
I cannot seem to get this to work. I'm getting this error:
ERROR: operator does not exist: timestamp without time zone * interval
SQL state: 42883
Hint: No operator matches the given name and argument type(s).
You might need to add explicit type casts.
The ALTER TABLE statement looks very straight-foward. But I've tried all kinds of casts and converting column-types, but can not get this to work. What am I missing?
The example in the Postgres manual (as well as the working fiddle by #mvp) transform an integer column (representing a UNIX epoch) to timestamptz.
The error message as well as your title clearly indicate you are trying to convert a timestamp to timestamptz. And this just works automatically, without explicit cast.
ALTER TABLE test ALTER created_at TYPE timestamptz;
-> SQLfiddle.
More about timestamp vs. timestamptz:
Ignoring timezones altogether in Rails and PostgreSQL
timestamp values are always interpreted according to the time zone setting of your session. To assume the time zone UTC for the conversion:
BEGIN;
SET LOCAL timezone='UTC';
ALTER TABLE test ALTER created_at TYPE timestamptz;
COMMIT;
Or use the AT TIME ZONE construct:
ALTER TABLE test ALTER created_at TYPE timestamptz
USING created_at AT TIME ZONE 'UTC';
You can assume any time zone this way.
It works fine for me: SQLFiddle.
I think what you have is your SQL client caching data types. I had this issue with mine until I restarted it, and type was indeed changed fine.