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

5 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
  4. kesaksian nyata dan kabar baik !!!

    Nama saya mohammad, saya baru saja menerima pinjaman saya dan telah dipindahkan ke rekening bank saya, beberapa hari yang lalu saya melamar ke Perusahaan Pinjaman Dangote melalui Lady Jane (Ladyjanealice@gmail.com), saya bertanya kepada Lady jane tentang persyaratan Dangote Loan Perusahaan dan wanita jane mengatakan kepada saya bahwa jika saya memiliki semua persyarataan bahwa pinjaman saya akan ditransfer kepada saya tanpa penundaan

    Dan percayalah sekarang karena pinjaman rp11milyar saya dengan tingkat bunga 2% untuk bisnis Tambang Batubara saya baru saja disetujui dan dipindahkan ke akun saya, ini adalah mimpi yang akan datang, saya berjanji kepada Lady jane bahwa saya akan mengatakan kepada dunia apakah ini benar? dan saya akan memberitahu dunia sekarang karena ini benar

    Anda tidak perlu membayar biayaa pendaftaran, biaya lisensi, mematuhi Perusahaan Pinjaman Dangote dan Anda akan mendapatkan pinjaman Anda

    untuk lebih jelasnya hubungi saya via email: mahammadismali234@gmail.com
    dan hubungi Dangote Loan Company untuk pinjaman Anda sekarang melalui email Dangotegrouploandepartment@gmail.com

    ReplyDelete
  5. Selamat siang pak / nyonya

    Kami menyambut Anda ke PERUSAHAAN PINJAMAN ELIZEBETH ISAAC, di mana kami memberikan pinjaman asli dan serius seperti:



    LAYANAN PINJAMAN TERSEDIA TERMASUK:
    ================================
    * Pinjaman Komersial.
    * Pinjaman pribadi.
    * Pinjaman Bisnis.
    * Pinjaman Investasi.
    * Pinjaman Pembangunan.
    * Pinjaman Akuisisi.
    * Pinjaman konstruksi.
    * Pinjaman Kartu Kredit
    * Pinjaman Konsolidasi Utang
    * Pinjaman bisnis dan lainnya:

    Kami memberikan pinjaman bunga 2% tanpa agunan, sehingga kami dapat mengatakan bahwa kami memberikan PINJAMAN TANPA Agunan, Anda tidak perlu merasa buruk atau kecewa dengan bank yang meminta agunan, cukup hubungi kami dengan mengirim email kepada kami di:

    elizebethisaac@gmail.com

    Terima kasih

    kami menunggu untuk mendengar dari Anda segera

    ReplyDelete