Script to get duration I am new to PostgreSQL. I am trying to write a query which can give me duration of the time. The fields are in the format yyyymmddhhmmss. In between we will get empty fields for Start_Time or End_Time. I want to skip these rows and get the output.

Start_Time          End_Time 
20130312080535   20130312080550
20130312080018   20130312080028
20130312080030   20130312080049
20130311154049   20130311154138
20130311225510  
20130311152500   20130311152538
20130311225510  
20130311152539   20130311152614
20130311152740   20130311152806
Something like this?

SELECT
  to_timestamp(end_time, 'YYYYMMDDHH24MISS') -
  to_timestamp(start_time, 'YYYYMMDDHH24MISS') as "time_interval"
FROM
  measurement
WHERE
  end_time IS NOT NULL;


There's an sqlfiddle if you want to adjust your question: http://sqlfiddle.com/#!1/576d4/6