![]() To get the current time with a specific precision, you use the CURRENT_TIME(precision) function: SELECT CURRENT_TIME( 5) To get the current time with time zone, you use the CURRENT_TIME function as follows: SELECT CURRENT_TIME Ĭode language: SQL (Structured Query Language) ( sql ) The following illustrates the TIME with time zone values: 04:05:06 PSTĠ4:05:06.789-8 Code language: SQL (Structured Query Language) ( sql ) Handling PostgreSQL TIME values Getting the current time The storage size of the TIME with time zone data type is 12 bytes that allow you store a time value with the time zone that ranges from 00:00:00+1459 to 24:00:00-1459. The following statement illustrates how to declare a column whose data type is TIME with time zone: column TIME with time zone Code language: SQL (Structured Query Language) ( sql ) Third, query data from the shifts table: SELECT * FROM shifts Code language: SQL (Structured Query Language) ( sql ) PostgreSQL TIME with time zone typeīesides the TIME data type, PostgreSQL provides the TIME with time zone data type that allows you to store and manipulate the time of day with time zone. Second, insert some rows into the shifts table: INSERT INTO shifts(shift_name, start_at, end_at) ) Code language: SQL (Structured Query Language) ( sql ) Consider the following example.įirst, create a new table named shifts by using the following CREATE TABLE statement: CREATE TABLE shifts ( We often use the TIME data type for the columns that store the time of day only e.g., the time of an event or a shift. PostgreSQL actually accepts almost any reasonable TIME format including SQL-compatible, ISO 8601, etc. HHMISS.pppppp Code language: SQL (Structured Query Language) ( sql ) If you want to use the precision, you can use the following formats: MI:SS.pppppp HHMISS Code language: SQL (Structured Query Language) ( sql )Ġ10203 Code language: SQL (Structured Query Language) ( sql ) The following illustrates the common formats of the TIME values: HH:MI The TIME data type requires 8 bytes and its allowed range is from 00:00:00 to 24:00:00. The precision specifies the number of fractional digits placed in the second field. The following statement illustrates how to declare a column with the TIME data type: column_name TIME(precision) Code language: SQL (Structured Query Language) ( sql )Ī time value may have a precision up to 6 digits. ![]() ![]() ![]() PostgreSQL provides the TIME data type that allows you to store the time of day values. Introduction to PostgreSQL TIME data type Summary: in this tutorial, we will introduce you to the PostgreSQL TIME data types and show you some handy functions to handle time values. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |