Connecting Tech Pros Worldwide Help | Site Map

Lexical question...

  #1  
Old November 23rd, 2005, 03:02 AM
Net Virtual Mailing Lists
Guest
 
Posts: n/a
Hello,

I have a table with a timestamp column and I want to set this to a value
of now() - a random number of days between 0 and 45 for each row... I've
tried to do this a bunch of different ways and can't figure it out...
Here is my latest version:


update sometable set entered_dt = now() - interval round(random()*45)||'
days';


Any ideas on the proper way to accomplish this?

Thanks!

- Greg




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

  #2  
Old November 23rd, 2005, 03:02 AM
Net Virtual Mailing Lists
Guest
 
Posts: n/a

re: Lexical question...


Err, I just read my latest digest and saw the solution:

update datafrenzy.jobdata set entered_dt= now() - CAST(round(random()*45)
|| ' days' AS interval);


- Greg
[color=blue]
>Hello,
>
>I have a table with a timestamp column and I want to set this to a value
>of now() - a random number of days between 0 and 45 for each row... I've
>tried to do this a bunch of different ways and can't figure it out...
>Here is my latest version:
>
>
>update sometable set entered_dt = now() - interval round(random()*45)||'
>days';
>
>
>Any ideas on the proper way to accomplish this?
>
>Thanks!
>
>- Greg
>[/color]



---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

  #3  
Old November 23rd, 2005, 03:02 AM
John DeSoi
Guest
 
Posts: n/a

re: Lexical question...



On Nov 23, 2004, at 5:33 AM, Net Virtual Mailing Lists wrote:
[color=blue]
> I have a table with a timestamp column and I want to set this to a
> value
> of now() - a random number of days between 0 and 45 for each row...
> I've
> tried to do this a bunch of different ways and can't figure it out...
> Here is my latest version:
>
>
> update sometable set entered_dt = now() - interval
> round(random()*45)||'
> days';
>[/color]

Try

select now() - ((round(random()*45))::text || ' days')::interval;

Best,

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL



---------------------------(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

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
fgets question Bill Cunningham answers 26 June 27th, 2008 08:41 PM
Re: Instance question Chris O answers 0 June 27th, 2008 06:05 PM
Design pattern question alebcn75@gmail.com answers 5 June 9th, 2007 10:15 PM
C, lexical Lucas Zimmerman answers 13 November 15th, 2005 03:07 AM