首页 > 数据库 >TIMESTAMP WITH TIME ZONE in PG and Oracle

TIMESTAMP WITH TIME ZONE in PG and Oracle

时间:2024-04-23 10:00:44浏览次数:26  
标签:PostgreSQL ZONE zone TIMESTAMP TIME PG time Oracle


Both Oracle and PostgreSQL support the TIMESTAMP WITH TIME ZONE data type, but there are some differences in how they handle and store time zone information.

Storage:

Oracle: In Oracle, TIMESTAMP WITH TIME ZONE values are stored in UTC internally. The time zone offset is stored alongside the timestamp to indicate the original time zone of the input value.
PostgreSQL: In PostgreSQL, TIMESTAMP WITH TIME ZONE values are stored as UTC internally as well. However, the time zone offset is not stored directly with the timestamp. Instead, the timestamp is stored along with the time zone identifier, which allows PostgreSQL to calculate the appropriate time zone offset when retrieving the data.
Time zone conversion:

Oracle: Oracle performs automatic time zone conversions when working with TIMESTAMP WITH TIME ZONE values. When you insert a value into a column of this type, Oracle converts it to UTC based on the provided time zone offset or time zone region.
PostgreSQL: PostgreSQL does not perform automatic time zone conversions. When you insert a TIMESTAMP WITH TIME ZONE value, it is stored as provided. When retrieving the value, PostgreSQL applies the appropriate time zone conversion based on the current session time zone setting.
Time zone handling:

Oracle: Oracle uses time zone regions to handle TIMESTAMP WITH TIME ZONE values. Time zone regions are named regions that include the necessary information to determine the time zone offset for a specific location. Oracle provides a set of predefined time zone regions, and you can also define your own.
PostgreSQL: PostgreSQL uses the IANA (Internet Assigned Numbers Authority) time zone database to handle TIMESTAMP WITH TIME ZONE values. It supports a wide range of time zones and uses standard time zone names like 'America/New_York' or 'Europe/Paris'.
Display format:

Oracle: Oracle uses a specific format to display TIMESTAMP WITH TIME ZONE values, which includes the date, time, and time zone offset. For example, 'YYYY-MM-DD HH:MI:SS.FF TZH:TZM'.
PostgreSQL: PostgreSQL also has its own format for displaying TIMESTAMP WITH TIME ZONE values, which includes the date, time, and time zone offset. The format is similar to Oracle's and follows the ISO 8601 standard. For example, 'YYYY-MM-DD HH:MI:SS.FF+TZH:TZM'.
It's important to note that while the underlying storage and behavior may differ, both Oracle and PostgreSQL provide ways to work with TIMESTAMP WITH TIME ZONE values and perform time zone conversions when needed. The specific syntax and functions may vary between the two databases, so it's recommended to refer to the respective documentation for detailed information.

Certainly! Here are some additional details about TIMESTAMP WITH TIME ZONE in Oracle and PostgreSQL:

Time zone adjustments:

Oracle: Oracle automatically adjusts TIMESTAMP WITH TIME ZONE values to the session time zone when queried. The conversion is performed based on the time zone offset or time zone region associated with the data. This ensures that the values are presented in the appropriate time zone for the user or application.
PostgreSQL: In PostgreSQL, the time zone conversion is performed based on the current session time zone setting. When retrieving a TIMESTAMP WITH TIME ZONE value, PostgreSQL applies the necessary adjustment to convert it to the session time zone. This allows users to see the values in their preferred time zone.
Time zone support:

Oracle: Oracle supports a wide range of time zones and provides built-in functions for working with TIMESTAMP WITH TIME ZONE values. It includes functions for converting between time zones, extracting time zone information, and manipulating timestamps with respect to time zones.
PostgreSQL: PostgreSQL also supports a comprehensive set of time zones using the IANA time zone database. It offers various functions and operators for time zone conversions, extracting time zone information, and performing calculations involving time zones.
Time zone offsets:

Oracle: In Oracle, TIMESTAMP WITH TIME ZONE values can include a time zone offset in the format '+HH:MM' or '-HH:MM'. The offset represents the difference between the local time zone and Coordinated Universal Time (UTC).
PostgreSQL: Similarly, PostgreSQL allows TIMESTAMP WITH TIME ZONE values to include a time zone offset. The offset is specified as '+HH:MM', '-HH:MM', or as a numeric value representing the offset in hours.
DST transitions:

Oracle: Oracle handles Daylight Saving Time (DST) transitions automatically when working with TIMESTAMP WITH TIME ZONE values. It takes into account the DST rules defined for the specific time zone region and adjusts the timestamps accordingly.
PostgreSQL: PostgreSQL also considers DST transitions based on the time zone database it uses. It accurately handles the changes in time zone offsets that occur during DST transitions.
Compatibility considerations:

When migrating from Oracle to PostgreSQL or vice versa, it's important to consider the differences in how TIMESTAMP WITH TIME ZONE values are stored, handled, and displayed. It may require adjustments to the code or queries that deal with timestamps and time zones.
Remember to consult the documentation of the respective database systems for precise details on working with TIMESTAMP WITH TIME ZONE data types as the capabilities and syntax may evolve over time.


Here are some more details about TIMESTAMP WITH TIME ZONE in Oracle and PostgreSQL:

Timestamp precision:

Oracle: In Oracle, TIMESTAMP WITH TIME ZONE supports fractional seconds with a precision of up to 9 digits. You can specify the precision when defining the column or variable.
PostgreSQL: Similarly, PostgreSQL allows fractional seconds in TIMESTAMP WITH TIME ZONE values with a precision of up to 6 digits. The precision is specified when defining the column or variable.
Time zone conversion functions:

Oracle: Oracle provides a range of built-in functions for manipulating TIMESTAMP WITH TIME ZONE values and performing time zone conversions. Some commonly used functions include FROM_TZ, AT TIME ZONE, and SYS_EXTRACT_UTC.
PostgreSQL: PostgreSQL offers functions and operators for working with TIMESTAMP WITH TIME ZONE values. Functions like AT TIME ZONE, TIMEZONE, and TO_TIMESTAMP are commonly used to handle time zone conversions and extract time zone information.
Time zone abbreviations:

Oracle: Oracle supports time zone abbreviations such as 'PST' (Pacific Standard Time) or 'EST' (Eastern Standard Time). However, it's important to note that time zone abbreviations are not unique and can lead to ambiguity.
PostgreSQL: PostgreSQL does not rely heavily on time zone abbreviations. Instead, it primarily uses time zone names in the format 'America/New_York' or 'Europe/Paris', which are standardized and less prone to ambiguity.
Time zone region settings:

Oracle: In Oracle, the time zone region is set at the database level using the DBTIMEZONE parameter. This parameter defines the default time zone for TIMESTAMP WITH TIME ZONE values stored in the database.
PostgreSQL: PostgreSQL allows you to set the time zone at the database level using the timezone configuration parameter. This parameter sets the default time zone for the entire database and affects the behavior of TIMESTAMP WITH TIME ZONE values.
Handling invalid time zone offsets:

Oracle: Oracle handles invalid time zone offsets by adjusting the TIMESTAMP WITH TIME ZONE values to a valid offset. For example, if an invalid offset is specified, Oracle adjusts it to the nearest valid offset based on the historical offset information available.
PostgreSQL: PostgreSQL does not automatically adjust invalid time zone offsets. If an invalid offset is provided, PostgreSQL raises an error and does not store the value.
It's important to keep in mind that the behavior and features of TIMESTAMP WITH TIME ZONE may be subject to version-specific differences in both Oracle and PostgreSQL. Therefore, referring to the documentation and specific version information is crucial for accurate understanding and usage.



标签:PostgreSQL,ZONE,zone,TIMESTAMP,TIME,PG,time,Oracle
From: https://www.cnblogs.com/Jeona/p/18152199

相关文章

  • ORACLE定时器,执行周期设定
    对于DBA来说,数据库Job再熟悉不过了,因为经常要数据库定时的自动执行一些脚本,或做数据库备份,或做数据的提炼,或做数据库的性能优化,包括重建索引等等的工作。但是,Oracle定时器Job时间的处理上,千变万化,今天我把比较常用写法汇总如下:在总结之前,先把Job的参数一一说明一下:job参数是由Su......
  • oracle 修改密码不过期
    1.以sysdba身份进入sqlplus模式 2.查看用户密码的有效期设置一般默认的配置文件是DEFAULTSELECT*FROMdba_profilesWHEREprofile='DEFAULT'ANDresource_name='PASSWORD_LIFE_TIME';3.将密码有效期修改成“无限期”ALTERPROFILEDEFAULTLIMITPASSWORD_LIFE_TIM......
  • 基于EP4CE6F17C8的FPGA矩阵键盘实例(另类方法)
    一、电路模块电路模块参见“基于EP4CE6F17C8的FPGA矩阵键盘实例”部分。二、实验代码本例使用6个数码管依次显示按下按键的键值,每位显示的值可从0~F,对应16个矩阵按键。按键reset为复位键,代码使用Verilog编写,具体如下。先编写数码管实现显示字形解码的程序,模块名称为seg_decode......
  • C++ 连接pg数据库
    环境:windows10vs2022引入pqxxs一些增删改查的示例代码#include"pqxx/pqxx"voidinsertPg(){try{//建立连接pqxx::connectionconn("dbname=postgresuser=postgrespassword=123hostaddr=127.0.0.1port=5432");//添加数据......
  • Oracle JDK 和 OpenJDK 有什么区别?
    OpenJDK是Sun在2006年末把Java开源而形成的项目,这里的“开源”是通常意义上的源码开放形式,即源码是可被复用的,例如IcedTea、UltraViolet都是从OpenJDK源码衍生出的发行版。OracleJDK采用了商业实现,而OpenJDK使用的是开源的FreeType。当然,“相同”是建立在两者共有的组件基础上的,O......
  • m基于FPGA的多通道FIR滤波器verilog实现,包含testbench测试文件
    1.算法仿真效果VIVADO2019.2仿真结果如下:   系统RTL结构如下:   2.算法涉及理论知识概要       多通道FIR(FiniteImpulseResponse)滤波器是一种在数字信号处理中广泛应用的线性时不变滤波技术,尤其适用于多通道音频、视频、图像等多维数据的处理。   ......
  • [转帖]Oracle 败了、谷歌赢了:Java API 版权案最终裁决
    https://zhuanlan.zhihu.com/p/362496136 周一,最高法院在Oracle围绕移动操作系统Android中所用软件的一起旷日持久的版权诉讼中判谷歌胜诉。法院的判决为6比2。大法官AmyConeyBarrett没有参与此案。该案涉及谷歌用于构建Android的12000行代码,这些代码是从SunMicrosy......
  • Google和Oracle关于Java的知识产权诉讼
    Google和Oracle关于Java的知识产权诉讼背景Oracle收购SUN之后立即对Oracle展开了诉讼.经历了多级法院的上诉和驳回.2021.4.5美国联邦最高法院判断.Google不侵权.无需赔偿Oracle提起的80亿美金的诉讼但是专利官司在美国科技史上影响很大.AMD跟Intel的关于x86......
  • 错误:System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本问题
    最近在虚拟机上搭一套新的开发环境,运行项目时报错。如果你的系统中已经安装了Oracle客户端软件,那么可能需要检查一些环境变量。例如,你可以通过在系统的环境变量中设置PATH变量来包含Oracle客户端的路径,这样可以帮助.NET框架找到所需的Oracle客户端软件。此外,如果你的Oracle客户......
  • [code notes] ecpg precompiler 1
    Thisnotewillintroducetheworkflowofparse.ploftheecpgprecompiler.Runtheprecompiler:perlparse.pl.../../../backend/parser/gram.yworkflowloadecpg.addonsintoanmemoryhashtable.Thekeyiscomposedofstringliteralsfromaproduction......