Interval Type for Durations in PostgreSQL
📖 Scenario: You are managing a project timeline database. You want to store durations of tasks using PostgreSQL's INTERVAL type to represent time spans like days, hours, and minutes.
🎯 Goal: Create a table to store task names and their durations using the INTERVAL type. Insert sample data with specific durations, then query the table to find tasks longer than a certain duration.
📋 What You'll Learn
Create a table named
tasks with columns task_name (text) and duration (INTERVAL).Insert three tasks with durations: 'Design' - 3 days, 'Development' - 5 days 4 hours, 'Testing' - 2 days 6 hours.
Create a variable or use a value to represent a duration threshold of 3 days.
Write a query to select task names and durations where the duration is greater than the threshold.
💡 Why This Matters
🌍 Real World
Managing project timelines and durations in databases is common in software development, event planning, and operations.
💼 Career
Understanding how to use INTERVAL types helps database administrators and developers handle time durations efficiently.
Progress0 / 4 steps