functions in postgresql!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • artistlikeu
    New Member
    • Nov 2006
    • 38

    #1

    functions in postgresql!!!

    i have a table of car. In my table there is a column of time which stores traveling time of individual car in "HH:MM:SS" format. I write a query and get time in the same format. i will write my problem below.

    Can i write a function for this table that whenever i select this column, i must get time in seconds i.e integers.

    thnx
    @rtist
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    Did you try to use a format function?
    select to_char(column-name, 'SSSS') ;

    Comment

    • artistlikeu
      New Member
      • Nov 2006
      • 38

      #3
      thnx a lot... it is working now....

      can i define it as a function rather than using query all the time... may be as views.???

      if so plz can u guide me...
      regards

      Comment

      • michaelb
        Recognized Expert Contributor
        • Nov 2006
        • 534

        #4
        Of course you can have your own function, or you can create a view... but why bother?

        - you would still run a query to execute your function and you can hardly expect it'll be better or faster than the one you're using now.

        - a view does have its advantages, but let's first understand what seems to be inefficient with using a function inside your query.

        Suppose what you had before looks like this:
        select field1, field2, field3 from myTable;
        And this is what you have now:
        select field1, to_char(field2, 'SSSS'), field3 from myTable;

        Again, depending on your situation a view may have a perfect sense, but you need to see a reason why would you benefit from it.
        Perhaps it'll help if you provide more details.

        michael.

        Comment

        Working...