Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datetime variable type deprecated in PostgreSQL 9.0.x?

I'm querying an external API and want to test out data inserts on a test server before moving to production.

Currently, I'm trying to execute the following statement in Postgres's shell:

CREATE TABLE referrals (client_id VARCHAR(36), device_id VARCHAR(100), conversion_time DATETIME, acquisition_cost MONEY);

but it keeps failing on DATETIME.

Since this doesn't work, would timestamp? If so, how do I modify timestamp's default behavior to take in preformatted dates and times?

like image 682
Edwin Avatar asked Jan 19 '23 04:01

Edwin


1 Answers

CREATE TABLE referrals (
  client_id text 
, device_id text 
, conversion_time timestamp
, acquisition_cost money
);

You don't have to add without time zone, that is the default.

I use the type text in the example instead of varchar with a length modifier, because that is usually the better choice. You can use varchar(n) of course, no problem.

locale and DateStyle settings influence how text input for date / timestamp values is interpreted. Use the functions to_date() or to_timestamp() to be largely independent of local settings:

SELECT to_timestamp('05 Dec 2000', 'DD Mon YYYY');

More in the chapter Data Type Formatting Functions of the fine manual.

like image 154
Erwin Brandstetter Avatar answered Jan 20 '23 19:01

Erwin Brandstetter