dbTalk Databases Forums  

Lexical question...

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss Lexical question... in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Net Virtual Mailing Lists
 
Posts: n/a

Default Lexical question... - 11-23-2004 , 04:33 AM






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


Reply With Quote
  #2  
Old   
Net Virtual Mailing Lists
 
Posts: n/a

Default Re: Lexical question... - 11-23-2004 , 04:47 AM






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

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

- Greg

Quote:
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 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly



Reply With Quote
  #3  
Old   
John DeSoi
 
Posts: n/a

Default Re: Lexical question... - 11-23-2004 , 08:03 AM




On Nov 23, 2004, at 5:33 AM, Net Virtual Mailing Lists wrote:

Quote:
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';

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



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.