Database Management PostgreSQL Subjective
Sep 25, 2025

What are PostgreSQL range types and their applications?

Detailed Explanation

Range types represent ranges of values with support for bounds and operations.

Built-in Range Types:
• int4range, int8range: Integer ranges
• numrange: Numeric ranges
• tsrange: Timestamp ranges
• daterange: Date ranges

Example:

-- Create table with range column
CREATE TABLE reservations (
id SERIAL PRIMARY KEY,
room_id INT,
period tsrange
);

-- Insert reservation
INSERT INTO reservations (room_id, period)
VALUES (101, '[2024-01-01 10:00, 2024-01-01 12:00)');

-- Check for overlaps
SELECT * FROM reservations
WHERE period && '[2024-01-01 11:00, 2024-01-01 13:00)';

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback