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