Choosing PostgreSQL Column Types for IDs, Amounts, Text, and Dates
Choose PostgreSQL types for IDs, amounts, quantities, strings, and dates, with illustrative SQL to check limits and application round-trips.

If an application stores an order ID, an amount, a quantity, a label, and two kinds of time value, choose their column types from what those values mean. Use an integer type for whole numbers, numeric when a decimal value must be exact, and a string type whose length and padding rules match the input. Use date for a calendar date; decide explicitly whether a timestamp includes a time zone. The schema is only the first check: values must also survive the application's input and output conversions.
Start with the value, not the type name
Consider an order record with a whole-number identifier and a count of items. PostgreSQL documents smallint, integer, and bigint as signed two-, four-, and eight-byte integers, respectively. Choose a width that accommodates the values the application must represent. The example below uses bigint for the ID and integer for a whole-number quantity. Neither choice implies that the ID is generated automatically or that every quantity must be whole.
An amount such as 19.95 has a different requirement: its decimal value must be exact. PostgreSQL documents numeric as an exact numeric type with selectable precision, whereas double precision is floating point. That distinction is enough to choose numeric for an exact application amount or a fractional quantity that also needs exact decimal representation. Decide the required precision and scale from the application's valid values rather than copying the example declaration unchanged. The PostgreSQL 14 type table documents these type descriptions.
This table is illustrative SQL, not a report of an executed test. It keeps both timestamp forms visible because they represent different application decisions:
CREATE TABLE order_type_example (
order_id bigint,
amount numeric(12, 2),
item_quantity integer,
description text,
short_label character varying(8),
order_date date,
local_recorded_at timestamp without time zone,
zoned_recorded_at timestamp with time zone
);
The declarations do not establish whether these are the right business limits. For example, a quantity that can be fractional calls for reconsidering integer; an amount that needs a different decimal precision calls for reconsidering numeric(12, 2).
Decide whether a string has a limit or padding
Use text when the schema does not need a declared character limit. Use character varying(n) when it does: its limit counts characters, not bytes. character(n) also has an n-character limit, but PostgreSQL pads its values with spaces to the declared width. That makes it a deliberate choice for values where fixed-width, space-padded behavior is wanted, not a default substitute for text.
There is an important difference between inserting an overlength value and explicitly casting one. An insertion into a constrained string column errors when the value is too long, unless the excess characters are all spaces; PostgreSQL truncates those excess spaces. An explicit cast to character varying(n) or character(n) instead truncates an overlength value without an error. These are documented string-type rules, not measurements from the example.
The following illustrative statements are intended to be tried separately after creating the table. The first insert should error because the label has nine non-space characters. The second explicitly casts that label to eight characters before inserting it, so it demonstrates a potentially unwanted loss of input:
INSERT INTO order_type_example (order_id, short_label)
VALUES (1, 'ABCDEFGHI');
INSERT INTO order_type_example (order_id, short_label)
VALUES (2, 'ABCDEFGHI'::character varying(8));
SELECT order_id, short_label
FROM order_type_example
WHERE order_id = 2;
If preserving the original label matters, do not use an explicit cast as a way around the column limit. Reject or handle that input at the application boundary instead.
Separate calendar dates from timestamps
date represents a calendar date, consisting of year, month, and day. Use it for a value such as an order's calendar date when no time of day is part of the value. For a date and time, choose explicitly between timestamp without time zone and timestamp with time zone according to whether the represented value includes a time zone. An unqualified timestamp means timestamp without time zone in PostgreSQL, so spelling out the declaration makes the choice easier to review. The date/time documentation describes that distinction.
Use ISO 8601 date input instead of a date whose field order could change meaning with DateStyle. PostgreSQL recommends the following form as unambiguous across its date input modes:
INSERT INTO order_type_example (order_id, order_date)
VALUES (3, DATE '2025-01-08');
That statement is illustrative; it has not been executed here. If the application sends timestamps, check its actual input and output representation as well. Choosing a column type does not, by itself, verify what the application serializes.
Check the boundary that uses the schema
Review the declared types in the migration, then send representative values through the same application input and output path that will use the table. Include the largest expected ID, an amount and quantity with the required decimal digits, a label at the limit, a label beyond it, an ISO-formatted calendar date, and values for each timestamp column. Compare what the application reads back with what it sent, rather than checking only that an insert succeeded.
This matters especially when values cross a format boundary. PostgreSQL's type documentation notes that data types have input and output functions and that some output conversions can lose accuracy relative to the original input. A round-trip check cannot replace deciding what a value means, but it can expose a mismatch between that decision and the application's representation before the schema becomes a dependency.

