Wednesday, July 6, 2011

Greenplum / PostgreSQL Function of the Day: age

How old is my customer?  How old is that order?  How old is our product widget?

When doing customer profiling and segmentation I often want to find a customer's age.  This is also useful for calculating the age of anything.  Luckily, PostgreSQL makes this easy and it's available in Greenplum 4.0.4.0: they have an age function.

The age(date) function will operate on dates through timestamps and return age in years all the way through to years, days, hours, minutes, and seconds.

For example, my sister was born on 7/4/1980.  If her date of birth was in my family table under date_of_birth I could calculate her age :

select age(date_of_birth) from family;

And the db would return 31.

If I wanted to ask, how long have I owned this asset, I could query the db:

select age(created_at) from assets where id = 11; 

And it would calculate the age from this minute as:

age_of_asset                        created_at
3 years 10 mons 14 days 14:59:15    2007-08-22 09:00:45

3 comments:

  1. Hello Everybody,
    My name is Mrs Sharon Sim. I live in Singapore and i am a happy woman today? and i told my self that any lender that rescue my family from our poor situation, i will refer any person that is looking for loan to him, he gave me happiness to me and my family, i was in need of a loan of S$250,000.00 to start my life all over as i am a single mother with 3 kids I met this honest and GOD fearing man loan lender that help me with a loan of S$250,000.00 SG. Dollar, he is a GOD fearing man, if you are in need of loan and you will pay back the loan please contact him tell him that is Mrs Sharon, that refer you to him. contact Dr Purva Pius,via email:(urgentloan22@gmail.com) Thank you.

    BORROWERS APPLICATION DETAILS


    1. Name Of Applicant in Full:……..
    2. Telephone Numbers:……….
    3. Address and Location:…….
    4. Amount in request………..
    5. Repayment Period:………..
    6. Purpose Of Loan………….
    7. country…………………
    8. phone…………………..
    9. occupation………………
    10.age/sex…………………
    11.Monthly Income…………..
    12.Email……………..

    Regards.
    Managements
    Email Kindly Contact: urgentloan22@gmail.com

    ReplyDelete
  2. Hello Everybody,
    My name is Mrs Sharon Sim. I live in Singapore and i am a happy woman today? and i told my self that any lender that rescue my family from our poor situation, i will refer any person that is looking for loan to him, he gave me happiness to me and my family, i was in need of a loan of S$250,000.00 to start my life all over as i am a single mother with 3 kids I met this honest and GOD fearing man loan lender that help me with a loan of S$250,000.00 SG. Dollar, he is a GOD fearing man, if you are in need of loan and you will pay back the loan please contact him tell him that is Mrs Sharon, that refer you to him. contact Dr Purva Pius,via email:(urgentloan22@gmail.com) Thank you.

    BORROWERS APPLICATION DETAILS


    1. Name Of Applicant in Full:……..
    2. Telephone Numbers:……….
    3. Address and Location:…….
    4. Amount in request………..
    5. Repayment Period:………..
    6. Purpose Of Loan………….
    7. country…………………
    8. phone…………………..
    9. occupation………………
    10.age/sex…………………
    11.Monthly Income…………..
    12.Email……………..

    Regards.
    Managements
    Email Kindly Contact: urgentloan22@gmail.com

    ReplyDelete
  3. My name is.Mrs.Anna Daniel. I live in Ukraine i am a happy woman today? i need to use this time to tell all people how i got my loan from this honest and God fearing man loan lender that help me with a loan of $84,000 please contact him. if you also need a loan without any problem he name is Dr Purva Pius email (urgentloan22@gmail.com) tell him that is Mrs.Anna Daniel that refer you to he contact Email (urgentloan22@gmail.com)

    ReplyDelete