What timestamp and timestamptz store in Postgres, why timestamp silently drops time zone offsets, how session time zones change what you read back, and the one case where a local time plus a zone name is the better choice.

Postgres has two timestamp types, and the names suggest that one stores a time zone and the other does not, which is only half right and the source of a lot of off-by-some-hours bugs.
Both take 8 bytes, but timestamptz stores an absolute instant while timestamp stores a wall-clock reading with no zone at all, and that difference decides which one fits each column.
The date/time types documentation describes timestamp with time zone as converting input to UTC using the given offset, or the session's TimeZone when none is given, and converting back on output. The zone itself is not stored, so there is no way to ask a timestamptz value which zone it was written in.
timestamp without time zone keeps exactly the digits you gave it and discards any offset in the input:
SET TimeZone = 'UTC';
CREATE TABLE t (local_ts timestamp, instant timestamptz);
INSERT INTO t VALUES ('2026-11-23 10:00:00+05', '2026-11-23 10:00:00+05');
SELECT * FROM t;
-- local_ts | instant
-- 2026-11-23 10:00:00 | 2026-11-23 05:00:00+00
SET TimeZone = 'Europe/Vienna';
SELECT * FROM t;
-- local_ts | instant
-- 2026-11-23 10:00:00 | 2026-11-23 06:00:00+01
The timestamp column lost five hours of information on insert, and nothing warned about it. The timestamptz column kept the instant and shows it in whatever zone the session uses.
Most backend timestamps record when something happened, and comparing, sorting or subtracting them only works if they are instants. The Postgres wiki's list of common mistakes recommends timestamptz for that reason, and the main ways timestamp goes wrong in practice are:
timestamp written as local time is ambiguous for the repeated hour in autumn, and two events an hour apart can look identical.timestamp keeps the digits of whatever zone the conversion used.AT TIME ZONE converts in both directions. On a timestamptz it returns the wall-clock time in that zone as a timestamp, and on a timestamp it interprets the digits as local time in that zone and returns a timestamptz:
-- Instant to local wall-clock time
SELECT now() AT TIME ZONE 'America/New_York';
-- Local wall-clock time to instant; 02:30 does not exist on this date in Vienna
SELECT '2026-03-29 02:30'::timestamp AT TIME ZONE 'Europe/Vienna';
-- 2026-03-29 03:30:00+02
The second query shows a daylight saving gap: 02:30 never happens in Vienna that night, and Postgres shifts it forward rather than raising an error, so validate local times that users enter for that date.
Future events tied to a place, such as a dentist appointment at 09:00 in Vienna next June, are the one common exception. Time zone rules change by law, and the IANA time zone database ships several updates a year, so converting that appointment to UTC today can produce the wrong instant if the rules for that zone change before June.
Store those as a timestamp plus a text column with the IANA zone name, and compute the instant when you need it with starts_local AT TIME ZONE zone. Recurring local times, such as opening hours or "every weekday at 08:00", belong in time plus a zone for the same reason.
Best fit: timestamptz for every instant, and timestamp plus a zone name only for future or recurring local times.
Encore is a backend framework with built-in infrastructure, so column types are decided in the service's own migration and the endpoint that reads them sits beside it. This appointments service uses both patterns, an instant for when the booking was made and a local time plus zone for when the appointment happens:
Run in your terminal to get started locally.
-- appointments/migrations/1_create_appointments.up.sql
CREATE TABLE appointments (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
patient_id text NOT NULL,
starts_local timestamp NOT NULL,
zone text NOT NULL,
booked_at timestamptz NOT NULL DEFAULT now()
);
// appointments/appointments.go
package appointments
import (
"context"
"time"
"encore.dev/beta/errs"
"encore.dev/storage/sqldb"
)
var db = sqldb.NewDatabase("appointments", sqldb.DatabaseConfig{Migrations: "./migrations"})
type BookParams struct {
PatientID string `json:"patient_id"`
StartsLocal string `json:"starts_local"` // "2027-06-14T09:00"
Zone string `json:"zone"` // "Europe/Vienna"
}
type Booking struct {
ID int64 `json:"id"`
StartsAt time.Time `json:"starts_at"`
BookedAt time.Time `json:"booked_at"`
}
//encore:api public method=POST path=/appointments
func Book(ctx context.Context, p *BookParams) (*Booking, error) {
loc, err := time.LoadLocation(p.Zone)
if err != nil {
return nil, &errs.Error{Code: errs.InvalidArgument, Message: "unknown time zone"}
}
local, err := time.ParseInLocation("2006-01-02T15:04", p.StartsLocal, loc)
if err != nil {
return nil, &errs.Error{Code: errs.InvalidArgument, Message: "starts_local must be YYYY-MM-DDTHH:MM"}
}
b := &Booking{}
err = db.QueryRow(ctx, `
INSERT INTO appointments (patient_id, starts_local, zone)
VALUES ($1, $2::timestamp, $3)
RETURNING id, starts_local AT TIME ZONE zone, booked_at
`, p.PatientID, local.Format("2006-01-02 15:04"), p.Zone).Scan(&b.ID, &b.StartsAt, &b.BookedAt)
if err != nil {
return nil, err
}
return b, nil
}
The endpoint validates the zone name and the local time in Go, stores the wall-clock digits and the zone, and returns the computed instant, so a client never sends a pre-converted UTC value that would go stale if the zone's rules change. The databases docs cover migrations and queries, the API errors docs list the error codes, and the local Postgres that encore run starts behaves the same as RDS or Cloud SQL in your account, provisioned as described in the GCP infrastructure docs.
An AI coding agent asked to add a paid_at or expires_at column copies the types in neighboring migrations, so getting timestamptz right in the first one sets the pattern for every column it adds after, and a test against the local database can pin the conversion behavior down.
Best fit: services that store both event times and user-facing local times and want one convention across every environment.
If the existing values were written in UTC, run SET TimeZone = 'UTC' and then ALTER TABLE orders ALTER COLUMN created_at TYPE timestamptz with no USING clause, which reinterprets the digits as UTC and, on a local Postgres 17 test, kept the same table file instead of rewriting it. Values written in another zone need USING created_at AT TIME ZONE 'Europe/Vienna', which rewrites the whole table under an exclusive lock, so on a large table add a new column, backfill it in batches and switch reads over instead.
Use timestamptz for anything that happened or will happen at a specific instant, such as created_at, paid_at or expires_at. Use timestamp without time zone only for a wall-clock time that has no zone of its own, and pair it with a zone name when it describes a future local event.
No. timestamptz converts the input to UTC and stores that instant in 8 bytes, the same size as timestamp. The original offset is not kept, and output is converted to the session's TimeZone setting.
A plain timestamp column ignores any time zone or offset in the input, so '2026-11-23 10:00:00+05' is stored as 10:00 with no zone. Change the column to timestamptz, or the offset is lost on every insert.
Declare the columns as timestamptz in the service's migration and pass time.Time values as query parameters. The same columns behave the same way on the local Postgres that encore run starts and on RDS or Cloud SQL in your account.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.