Jed Rembold
Wednesday, October 15, 2025
A transaction is best used to accomplish all of the following except for which?
DATE: holds a single individual dayTIME: holds a single individual timeTIMESTAMP or variants with
TIMESTAMPTZ: holds a combination of date and
time, along with a potential time zoneINTERVAL: holds a duration of timeEXTRACT( |||piece||| FROM |||datetime_value||| )date_part( |||piece|||, |||datetime_value||| )DOUBLE PRECISION value
of whatever part was requested| text | Description |
|---|---|
| century | What century the date is in. 1st century starts 0001-01-01★ |
| day | What day of the month |
| decade | The year divided by 10 |
| dow | The day of the week (0-6, starting with Sunday) |
| doy | The day of the year |
| epoch | Number of seconds since 1970-01-01 |
| hour | The current hour (0-23) |
| microseconds | The number of microseconds |
| text | Description |
|---|---|
| milliseconds | The number of milliseconds |
| minute | The minute |
| month | The month (1-12) |
| quarter | What quarter of the year (1-4) |
| second | The number of seconds |
| timezone | The timezone offset in seconds |
| timezone_hour | The timezone offset in hours |
| week | What week of the year. ISO weeks start on Monday |
| year | The year |
★ – If you disagree with this, please write your complaint to: Pope, Cathedral Saint-Peter of Roma, Vatican.
make_date( |||year|||, |||month|||, |||day||| ):
Returns a new DATE type valuemake_time( |||hour|||, |||minute|||, |||seconds||| ):
Returns a new TIME type value (with no
timezone)make_timestamptz(|||year|||,|||month|||,|||day|||,|||hour|||,|||minute|||,|||second|||,|||time zone|||):
Returns a new TIMESTAMPTZ type valuemake_timestamp and
make_interval also existDATE type values will
give just an INT (in days)TIMESTAMP type values
will give an INTERVAL, with the biggest
“unit” in daysage() function can
smooth over both and give units larger than days
age( |||datetime1|||, |||datetime2||| ):
Subtracts datetime2 from datetime1justify_interval( |||interval||| ), which
breaks intervals into divisions that don’t exceed a categories max
| function | description |
|---|---|
current_date |
Returns the current date |
current_time |
Returns the current time with timezone |
localtime |
Returns the current time without timezone |
current_timestamp★ |
Returns the current date and time with timezone |
localtimestamp |
Returns the current date and time without timezone |
★ – Postgres also offers the shorter
now() function to do the same
thing
current_timestamp has it
computed once at the start of a query
clock_timestamp() instead, which
will work the same way but be updated before every value written to the
tableSHOW timezone;SELECT * FROM pg_timezone_abbrevs;SELECT * FROM pg_timezone_names;Change your postgressql.conf file,
which controls your Postgres server. Only recommended if you have
permanently moved elsewhere and the database time zone has not updated
appropriately.
Set future queries in a single session to be from a new timezone:
SET timezone TO |||some timezone name|||;
localtime or
localtimestamp report!Transform a single query to be reported in a different time zone:
SELECT |||datetime column||| AT TIME ZONE |||tz name or abbrv||||
FROM |||table|||;