Data Types
The following is a list of datatypes available in PostgreSQL, which includes string, numeric, and date/time datatypes.
String Datatypes
The following are the String Datatypes in PostgreSQL:
Data Type Syntax |
Explanation |
char(size) |
Where size is the number of characters to store. Fixed-length strings. Space padded on right to equal size characters. |
character(size) |
Where size is the number of characters to store. Fixed-length strings. Space padded on right to equal size characters. |
varchar(size) |
Where size is the number of characters to store. Variable-length string. |
character varying(size) |
Where size is the number of characters to store. Variable-length string. |
text |
Variable-length string. |
Numeric Datatypes
The following are the Numeric Datatypes in PostgreSQL:
Data Type Syntax |
Explanation |
bit(size) |
Fixed-length bit string |
varbit(size) |
Variable-length bit string |
smallint |
Equivalent to int2. |
int |
Equivalent to int4. |
integer |
Equivalent to int4. |
bigint |
Big integer value which is equivalent to int8. |
smallserial |
Small auto-incrementing integer value which is equivalent to serial2. |
serial |
Auto-incrementing integer value which is equivalent to serial4. |
bigserial |
Big auto-incrementing integer value which is equivalent to serial8. |
numeric(m,d) |
Where m is the total digits and d is the number of digits after the decimal. |
double precision |
8 byte, double precision, floating-point number |
real |
4-byte, single precision, floating-point number |
money |
Currency value. |
bool |
Logical boolean data type - true or false |
boolean |
Logical boolean data type - true or false |
Date/Time Datatypes
The following are the Date/Time Datatypes in PostgreSQL:
Data Type Syntax |
Explanation |
date |
Displayed as 'YYYY-MM-DD'. |
timestamp |
Displayed as 'YYYY-MM-DD HH:MM:SS'. |
timestamp without time zone |
Displayed as 'YYYY-MM-DD HH:MM:SS'. |
timestamp with time zone |
Displayed as 'YYYY-MM-DD HH:MM:SS-TZ'. |
time |
Displayed as 'HH:MM:SS' with no time zone. |
time without time zone |
Displayed as 'HH:MM:SS' with no time zone. |
time with time zone |
Displayed as 'HH:MM:SS-TZ' with time zone. |