WikiGalaxy

Personalize

PostgreSQL SMALLINT

Definition:

The SMALLINT data type in PostgreSQL is a two-byte integer that can store numbers ranging from -32,768 to 32,767. It is typically used when you need to save space and do not require the larger range provided by other integer types.

Use Cases:

Ideal for storing small numeric values such as age, number of items, or other small-range integers where space optimization is crucial.

Syntax:

To define a column with the SMALLINT type, use the following syntax:


CREATE TABLE example_table (
  id SERIAL PRIMARY KEY,
  small_number SMALLINT
);
    

Advantages:

Using SMALLINT helps to reduce storage requirements for databases that handle large amounts of rows with small integer values.

Limitations:

The range is limited to -32,768 to 32,767, which might not be sufficient for some applications requiring larger numbers.

Example Query:

Here's how you can insert and retrieve data using SMALLINT:


INSERT INTO example_table (small_number) VALUES (12345);

SELECT * FROM example_table WHERE small_number = 12345;
    

Console Output:

id | small_number ---+-------------- 1 | 12345 (1 row)

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025