select birth_date,
cast(birth_date + ((extract(year from age(birth_date)) + 1) * interval '1' year) as date) as next_birthday
from person
where name = 'Bob'
व्यंजक (extract(year from age(birth_date)) + 1) * interval '1' year अगले जन्मदिन पर (पूर्ण) वर्षों में आयु की गणना करता है। इसे जन्म तिथि में जोड़ने पर, यह अगला जन्मदिन देता है।
वास्तविक date प्राप्त करने के लिए कास्ट आवश्यक है वापस, क्योंकि date + interval एक टाइमस्टैम्प (एक समय सहित) देता है।
अगर आप where को हटाते हैं शर्त, आपको सभी "अगले" जन्मदिन मिलेंगे।
आप आने वाले जन्मदिनों की एक सूची भी प्राप्त कर सकते हैं उदा। अगले 30 दिन कुछ इस तरह का उपयोग करते हुए:
select next_birthday,
next_birthday - current_date as days_until_next
from (
select birth_date,
cast(birth_date + ((extract(year from age(birth_date)) + 1) * interval '1' year) as date) as next_birthday
from person
) as upcoming
where upcoming.next_birthday <= current_date + 30
order by next_birthday;