Lexical question...

Started by Net Virtual Mailing Listsover 21 years ago4 messagesgeneral
Jump to latest
#1Net Virtual Mailing Lists
mailinglists@net-virtual.com

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

#2Net Virtual Mailing Lists
mailinglists@net-virtual.com
In reply to: Net Virtual Mailing Lists (#1)
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

Show quoted text

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

#3John DeSoi
desoi@pgedit.com
In reply to: Net Virtual Mailing Lists (#1)
Re: Lexical question...

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

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

#4Michael Fuhr
mike@fuhr.org
In reply to: John DeSoi (#3)
Re: Lexical question...

On Tue, Nov 23, 2004 at 09:03:26AM -0500, John DeSoi wrote:

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

Or one of the following (add round() if desired):

select now() - 45 * random() * interval'1 day';
select now() - random() * interval'45 day';

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