I am migrating to postgres from sql server.
Is there a way that I could do the following and have it still work? SELECT CAST('1/1/2018' AS datetime2) I have tried and failed with
CREATE TYPE datetime2 AS (date2 TIMESTAMP); --doesn't work
If you want to have datetime2 as a synonym for timestamp type in PostgreSQL then use domain instead of type:
create domain datetime2 as timestamp;
Then your cast will work as is:
SELECT CAST('1/1/2018' AS datetime2);
┌─────────────────────┐
│ datetime2 │
├─────────────────────┤
│ 2018-01-01 00:00:00 │
└─────────────────────┘
Except the name it will have same behavior as original timestamp type.
What you are doing in your question is to create composite type (record with single field date2 of timestamp type) which could be also highly useful but for another kinds of tasks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With