コンテンツへスキップ
uencoder

SQL データ 型 リファレンス

標準 および 一般的 SQL データ 型: numeric, 文字列, temporal, binary, および JSON.

Numeric Types

SQL numeric types fall into exact and approximate categories. Exact types include INTEGER, BIGINT, and NUMERIC with specified precision and scale, storing values without rounding. Approximate types FLOAT and REAL use floating-point representation and may introduce rounding errors. Choosing exact types for financial calculations avoids subtle precision loss. The precision and scale of NUMERIC determine the maximum digits and decimal places stored.

INTEGER
Whole number, typically 32-bit
42
BIGINT
Large whole number, 64-bit
9000000000
NUMERIC(p,s)
Exact decimal with precision and scale
NUMERIC(10,2)
REAL
Single-precision floating point
3.14
DOUBLE PRECISION
Double-precision floating point
3.14159265358979

String Types

Character string types include fixed-length CHAR, variable-length VARCHAR, and text types for unbounded strings. VARCHAR with a length limit is the most common choice for bounded strings. The distinction between character and byte strings matters for multi-byte encodings: CHARACTER VARYING counts characters while BYTE VARYING counts bytes. National character types (NCHAR) were designed for Unicode but are largely superseded by UTF-8 databases.

Temporal Types

SQL temporal types include DATE for calendar dates, TIME for times, TIMESTAMP for date-time combinations, and INTERVAL for durations. TIMESTAMP WITH TIME ZONE stores an offset or zone, while WITHOUT TIME ZONE discards zone information. Storing instants in UTC and converting at display time avoids ambiguity. Interval arithmetic enables adding durations to timestamps, though time zone transitions like DST require careful handling.

関連ツール

参考链接