[SQL] Simple Question

2005-01-11 Thread Terry Lee Tucker
Hello:

I'm trying to figure out how to convert a floating point value into an 
interval of time. I'm calculating the time required to drive from point A to 
point B. For the sake of this question, we'll just say it is miles/speed. So:

drv_time = 478 / 45.0;

The value of this is: 10.6222

Is there a way of converting this value to an interval. It seems that INTERVAL 
only works with a quoted literal value.

If I type:
rnd=# select interval '10.8444 hours';
  interval

 @ 10 hours 50 mins 40 secs
(1 row)

Anybody have an pointers?

Thanks...


 Work: 1-336-372-6812
 Cell: 1-336-363-4719
email: [EMAIL PROTECTED]

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [SQL] Simple Question

2005-01-11 Thread Terry Lee Tucker
I figured it out. This works:

travel_window INTERVAL;
drv_time FLOAT;

drv_time = miles / 45.0;-- drive time
travel_window = quote_literal(drv_time || '' hours'');

The variable, travel_window becomes:  @ 10 hours 50 mins 40 secs, which is 
what I wanted.

If anybody knows any other ways, I'd be interested in see that too.

On Tuesday 11 January 2005 04:42 pm, Terry Lee Tucker saith:
 Hello:

 I'm trying to figure out how to convert a floating point value into an
 interval of time. I'm calculating the time required to drive from point A
 to point B. For the sake of this question, we'll just say it is
 miles/speed. So:

 drv_time = 478 / 45.0;

 The value of this is: 10.6222

 Is there a way of converting this value to an interval. It seems that
 INTERVAL only works with a quoted literal value.

 If I type:
 rnd=# select interval '10.8444 hours';
   interval
 
  @ 10 hours 50 mins 40 secs
 (1 row)

 Anybody have an pointers?

 Thanks...


  Work: 1-336-372-6812
  Cell: 1-336-363-4719
 email: [EMAIL PROTECTED]

 ---(end of broadcast)---
 TIP 4: Don't 'kill -9' the postmaster

 Work: 1-336-372-6812
 Cell: 1-336-363-4719
email: [EMAIL PROTECTED]

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [SQL] Simple Question

2005-01-11 Thread Michael Fuhr
On Tue, Jan 11, 2005 at 04:42:21PM -0500, Terry Lee Tucker wrote:

 Subject: [SQL] Simple Question

Please use a more descriptive subject -- think about how somebody
looking at a list of 200 messages, all with subjects like Simple
Question or PostgreSQL Question, would decide to look at yours.

 drv_time = 478 / 45.0;
 
 The value of this is: 10.6222
 
 Is there a way of converting this value to an interval. It seems that 
 INTERVAL 
 only works with a quoted literal value.

You can do arithmetic on intervals:

SELECT 478 / 45.0 * interval'1 hour';

For more information, see Date/Time Functions and Operators in
the documentation.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [SQL] Simple Question

2005-01-11 Thread Guy Fraser
Convert to seconds first (3600 sec/hr) :

select (
 '3600'::int4 
 * '478'::int4 
 / '45.0'::float8
)::int4::reltime::interval ;
 interval
--
 10:37:20
(1 row)

I don't know if ::int4::reltime::interval is the best 
way to end up with an interval, but its the only way I 
could figure out how to do it off the top of my head.

On Tue, 2005-11-01 at 16:42 -0500, Terry Lee Tucker wrote:
 Hello:
 
 I'm trying to figure out how to convert a floating point value into an 
 interval of time. I'm calculating the time required to drive from point A to 
 point B. For the sake of this question, we'll just say it is miles/speed. So:
 
 drv_time = 478 / 45.0;
 
 The value of this is: 10.6222
 
 Is there a way of converting this value to an interval. It seems that 
 INTERVAL 
 only works with a quoted literal value.
 
 If I type:
 rnd=# select interval '10.8444 hours';
   interval
 
  @ 10 hours 50 mins 40 secs
 (1 row)
 
 Anybody have an pointers?
 
 Thanks...
 
 
  Work: 1-336-372-6812
  Cell: 1-336-363-4719
 email: [EMAIL PROTECTED]
 
 ---(end of broadcast)---
 TIP 4: Don't 'kill -9' the postmaster
 
-- 
Guy Fraser
Network Administrator
The Internet Centre
1-888-450-6787
(780)450-6787


---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [SQL] Simple Question

2005-01-11 Thread Stephan Szabo

On Tue, 11 Jan 2005, Terry Lee Tucker wrote:

 Hello:

 I'm trying to figure out how to convert a floating point value into an
 interval of time. I'm calculating the time required to drive from point A to
 point B. For the sake of this question, we'll just say it is miles/speed. So:

 drv_time = 478 / 45.0;

 The value of this is: 10.6222

I think something like
 478/45.0 * interval '1 hour'
may do what you want.

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [SQL] Simple Question

2005-01-11 Thread Terry Lee Tucker
Thank you for the reply in spite of the subject.

On Tuesday 11 January 2005 05:15 pm, Michael Fuhr saith:
 On Tue, Jan 11, 2005 at 04:42:21PM -0500, Terry Lee Tucker wrote:
  Subject: [SQL] Simple Question

 Please use a more descriptive subject -- think about how somebody
 looking at a list of 200 messages, all with subjects like Simple
 Question or PostgreSQL Question, would decide to look at yours.

I will do this in the future.


  drv_time = 478 / 45.0;
 
  The value of this is: 10.6222
 
  Is there a way of converting this value to an interval. It seems that
  INTERVAL only works with a quoted literal value.

 You can do arithmetic on intervals:

 SELECT 478 / 45.0 * interval'1 hour';

I like your soultion better than mine. Thanks for the answer.


 For more information, see Date/Time Functions and Operators in
 the documentation.

 --
 Michael Fuhr
 http://www.fuhr.org/~mfuhr/

 ---(end of broadcast)---
 TIP 8: explain analyze is your friend

 Work: 1-336-372-6812
 Cell: 1-336-363-4719
email: [EMAIL PROTECTED]

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [SQL] Simple Question

2005-01-11 Thread Terry Lee Tucker
Thanks for the reply. My answer was a little different than yours because I 
used 488 instead of 478. Well, that three ways so far ;o)

On Tuesday 11 January 2005 05:06 pm, Guy Fraser saith:
 Convert to seconds first (3600 sec/hr) :

 select (
  '3600'::int4
  * '478'::int4
  / '45.0'::float8
 )::int4::reltime::interval ;
  interval
 --
  10:37:20
 (1 row)

 I don't know if ::int4::reltime::interval is the best
 way to end up with an interval, but its the only way I
 could figure out how to do it off the top of my head.

 On Tue, 2005-11-01 at 16:42 -0500, Terry Lee Tucker wrote:
  Hello:
 
  I'm trying to figure out how to convert a floating point value into an
  interval of time. I'm calculating the time required to drive from point A
  to point B. For the sake of this question, we'll just say it is
  miles/speed. So:
 
  drv_time = 478 / 45.0;
 
  The value of this is: 10.6222
 
  Is there a way of converting this value to an interval. It seems that
  INTERVAL only works with a quoted literal value.
 
  If I type:
  rnd=# select interval '10.8444 hours';
interval
  
   @ 10 hours 50 mins 40 secs
  (1 row)
 
  Anybody have an pointers?
 
  Thanks...
 
 
   Work: 1-336-372-6812
   Cell: 1-336-363-4719
  email: [EMAIL PROTECTED]
 
  ---(end of broadcast)---
  TIP 4: Don't 'kill -9' the postmaster

 --
 Guy Fraser
 Network Administrator
 The Internet Centre
 1-888-450-6787
 (780)450-6787


 ---(end of broadcast)---
 TIP 8: explain analyze is your friend

 Work: 1-336-372-6812
 Cell: 1-336-363-4719
email: [EMAIL PROTECTED]

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [SQL] Simple Question

2005-01-11 Thread Tom Lane
Terry Lee Tucker [EMAIL PROTECTED] writes:
 I'm trying to figure out how to convert a floating point value into an 
 interval of time.

Use something like

regression=# select  (478 / 45.0) * '1 hour'::interval;
 ?column?
--
 10:37:20
(1 row)

... or whatever other scale factor you have in mind.

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [SQL] simple question!

2001-09-28 Thread Josh Berkus

Esteban,

  is there a command intersect? I mean  exist a union command, but
 I
 don't know if exist a intersect command.
 thanks

Yes.  There is also EXCEPT as well as INTERSECT and UNION.  See the
online docs, in SQL COMMANDS -- SELECT 

-Josh


__AGLIO DATABASE SOLUTIONS___
   Josh Berkus
  Complete information technology  [EMAIL PROTECTED]
   and data management solutions   (415) 565-7293
  for law firms, small businessesfax 621-2533
and non-profit organizations.  San Francisco

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



[SQL] Simple Question

2001-04-14 Thread Lonnie Cumberland

Hello All,

This may be the wrong mailing list for this question but I hope someone can
answer it for me as it is holding up my development progress.

I have now been able to compile the tutorial/complex.c functions and test them
out with no problems.

I made a copy of the Makefile, Makefile.global, and Makefile.port (Linux) from
the tutorial directory and made a simple modification for the paths. Now the
'c" files compile up just fine.

The problem is that this set up will not work if I make some C++ files. I think
that there is something wrong in one of the above makefiles for the g++
compiler and the needed options, but do not know where to find it.

I even made a copy of the "concat_text()" function from the manual and
saved one copy as a "c" file. It compiled just fine. I then renamed that same
file to "cc" for C++ and it compiled ok, but the psql command interperter gave
me some error that it could not find the function even thout it worked the
first time and I moade no other changes.

I also need to link in some other libraries like "libfile.a" that I have for
some of the functions that will be placed in my pgSQL interface but am not sure
hoe to do this as well with the default Makefiles.

Does someone have a simple Makefile that will allow me to compile up my C++
functions?

Cheers,
Lonnie


__
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://www.postgresql.org/search.mpl