postgresqlHow do I use PostgreSQL smallint data type?
The PostgreSQL smallint data type is a 2-byte integer that can hold values between -32768 and 32767. It is useful for storing small numbers such as counts, ages, or other numerical values that will not exceed the range of a smallint.
Example
CREATE TABLE my_table (
id SERIAL PRIMARY KEY,
age SMALLINT
);
This code creates a table called my_table
with two columns, id
and age
. The id
column is a serial data type which will auto-increment each time a new row is added to the table. The age
column is a smallint data type and will store the age of the person associated with each row.
Code explanation
CREATE TABLE
- Creates a table in the databaseid SERIAL PRIMARY KEY
- Creates a column calledid
and sets it to auto-increment when a new row is addedage SMALLINT
- Creates a column calledage
and sets it to the smallint data type
Helpful links
More of Postgresql
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I set the PostgreSQL work_mem parameter?
- How can I use PostgreSQL with YAML?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How do I install PostgreSQL and Zabbix on my system?
- How do I install and configure PostgreSQL on Ubuntu?
- How do I rename a table in PostgreSQL?
- How can I write a PostgreSQL query to retrieve JSON data?
- How can Zalando use PostgreSQL to improve its software development?
See more codes...