By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

functions in postgresql!!!

P: 38
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
Nov 10 '06 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 534
Did you try to use a format function?
select to_char(column-name, 'SSSS') ;
Nov 10 '06 #2

P: 38
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
Nov 14 '06 #3

Expert 100+
P: 534
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.
Nov 14 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.