I have a field in SQLite defined as
ended DATETIME default 0
We are porting to Postgres, which would be the most appropriate type in Postgres ... timestamp with or without timezone?
currently the enddate holds values like 1477330116408
Related
I created all my Postgres tables using knex timestampz and now I get this error when trying to query anything. One possible solution is to convert all the columns to timestamp without timezone, but could I keep timezone and solve this error with photon?
I have a table in Oracle with timestamp data in "JAN-16-15 05.10.14.034000000 PM".
When I created the table in postgresql with "col_name timestamp" it is showing data as "2015-01-16 17:10:14.034".
Any suggestions on how can set the column to get the data format as in postgre same to what I have in Oracle?
Timestamps (or dates or numbers) do not have any "format2. Neither in Postgres nor in Oracle or in any other relational database).
Any "format" you see, is applied by your SQL client displaying those values.
You need to configure your SQL client to use a different format for timestamp, or use the to_char() function to format the value as you want.
In particular, to get the format you desire, use
SELECT to_char(current_timestamp, 'MON-MM-YY HH.MI.SS.US000 AM');
The output format can be changed in psql by changing the DateStyle parameter, but I would strongly recommend to not change it away from the default ISO format as that also affects the input that is parsed.
How can I solve this error:
" django.db.utils.ProgrammingError: cannot cast type time without time zone to timestamp with time zone "
I got this while using the migrate command after changing my Django Database from sqllite to postgres. Is there a solution settings that I can add to solve it for all fields in my project with type DateTimeField and using Timestamp
time_created = models.DateTimeField(null=True, blank=True)
I kinda reset my Db it worked, by deleted db and doing migrate again ( i also deleted the migration files where i changed DateTimefield from TimeField ) u can also do it by altering it manually from postgresql as i didnt have much to lose here i just reset by database, hope it explains.
I have a table with this particular date column in PostgreSQL, I need to retrieve the all record based on one specific Id using Slick 2.0, I'm using Joda to manage the dates
MyTable
(
IdTable Int NOT NULL,
Name varchar(64),
Created_Date timestamp with time zone DEFAULT now()
)
Then I try to map it in Slick in this way:
val Created_Date: Column[Option[DateTime]] = columnOption[DateTime]
As soon as I add the Created_Date column in my table, the method to retrieve the records fails. What's the right way to map a datetime with time zone in Slick using Joda? Any recomendation?
To use a db type with a scala type, you need define a type mapper, which was used to convert between db raw data and scala object.
You can define yours by using slick MappedColumnType, since timestamp was already built-in supported by slick.
Here's the guide content for slick 2.0.3
But you can also employ other existing libraries, like: slick-pg, slick-joda-mapper.
I've been successful retrieving timestamp with time zone columns in Slick 2.x using:
def timestamp = column[Timestamp]("timestamp", O.Default(null))
I setup a postgres db that was installed on a server in the Central Time Zone so all the timestamp columns are in Central Time Zone.
Is there a way in postgres to change all the timezone columns in a database from CST to GMT? Is it a best practice to configure databases to use GMT?
Well, best practice is to avoid using TIMESTAMP type which does not know anything about timezones and to always use TIMESTAMPTZ (short for TIMESTAMP WITH TIME ZONE) type to store your timestamps.
TIMESTAMPTZ stores both timestamp in UTC and timezone in which timestamp was originally written to (like CST, PST or GMT+6). This allows you to always manipulate and display these columns correctly, no matter what current server or client timezone setting is.
You should be able to convert your existing TIMESTAMP columns into TIMESTAMPTZ using something like:
ALTER TABLE mytable ALTER COLUMN old_tstamp TYPE TIMESTAMPTZ
Before doing this, you should experiment on small dataset or maybe small test table on how conversion from TIMESTAMP to TIMESTAMPTZ is really working for you such that time zone information is preserved on your data.
If conversion does not work correctly, you can temporarily set timezone for current session (you need it only for conversion purposes) using statement like (use it before ALTER TABLE ... COLUMN ... TYPE):
SET timezone TO 'CST6CDT';
or
SET timezone TO 'UTC+6';
This will affect subsequent operations and conversions from TIMESTAMP to TIMESTAMPTZ - just make sure to get it right.
After you have converted all timestamps to TIMESTAMPTZ, server or client timezone setting (which defaults to current operating system timezone setting) is only useful for display purposes, as data manipulation will be always correct.