phinx icon indicating copy to clipboard operation
phinx copied to clipboard

Postgres timestamp with timezone support

Open glena opened this issue 11 years ago • 6 comments

Hi,

Is there any way or workaround to enable timestamp with timezone support for PostgreSQL databases?

I have been checking the code and adding this type to the adaptes seems not to be enough.

Thanks.

glena avatar Dec 22 '14 19:12 glena

Can you give an example of the required definition, or syntax, that would allow this to work? I'm not sure I understand where the limitation is. Thanks!

shadowhand avatar Dec 22 '14 19:12 shadowhand

Sure, between the data types for date/time supported by PgSQL (http://www.postgresql.org/docs/9.1/static/datatype-datetime.html) there are 2 different timestamps.

Timestamp without timezone (the one used when use the phinx timezone type) and with timezone which also stores the timezone related to the timestamp.

I didn't find a way to use the second.

glena avatar Dec 22 '14 19:12 glena

Is using timestamptz or timestamp with time zone the more common practice in the Postgres community?

shadowhand avatar Dec 22 '14 21:12 shadowhand

I can`t say if this is the most common practice but I helps a lot if you work with schedules and timezones, let's say that this is "the right way" to handle this type of issues because it let you abstract from more complex convertions.

I'm making a pull request with some little changes to add support and will link to this issue.

Thanks

glena avatar Dec 23 '14 12:12 glena

Now supporting using the boolean timezone option for columns, which is only used by Postgres:

$table->addColumn('due_date', 'timestamp', array('timezone' => true));

shadowhand avatar Dec 23 '14 22:12 shadowhand

If I want to work with DateTime? (not DateTimeTz). The difference are in the "microseconds": DateTime: 2016-08-04 14:34:34

DateTimeTz: 2016-08-04 14:34:34.367606

If I use:

$table->addColumn('due_date', 'timestamp', array('timezone' => true));

I get:

ADD COLUMN due_date timestamp without time zone

But, If I want DateTime (without microseconds) I must to do:

ADD COLUMN due_date timestamp(0) without time zone

But now way to do that with Phinx. Maybe if add the option "limit" in type "timestamp", this way I can add the numeric option in timestamp. eg:

$table->addColumn('due_date', 'timestamp', array('timezone' => true, 'limit' => 0));

celorodovalho avatar Sep 04 '16 17:09 celorodovalho