pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
incrementing by the second
3+ messages / 2 participants
[nested] [flat]

* incrementing by the second
@ 1999-04-27 20:13  JT Kirkpatrick <jt-kirkpatrick@mpsllc.com>
  0 siblings, 0 replies; 3+ messages in thread

From: JT Kirkpatrick @ 1999-04-27 20:13 UTC (permalink / raw)
  To: 'pgsql-sql@hub.org' <pgsql-sql@hub.org>

I have 96,000 records in a postgres table that has an unpopulated field for 
datetime.  I need the value in that field to be unique, but the ACTUAL 
value isn't really that important.  I'd like to begin with the first 
record, enter a date and time, and then increment that value by one second 
for the next field, one second for the next, and so on.  Can I do this 
directly from within psql??  I could do this in dbase w/ no problem, but 
I'm really not that familiar with sql syntax. . .

jt




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* RE: [SQL] incrementing by the second
@ 1999-04-27 20:41  Jackson, DeJuan <djackson@cpsgroup.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Jackson, DeJuan @ 1999-04-27 20:41 UTC (permalink / raw)
  To: JT Kirkpatrick <jt-kirkpatrick@mpsllc.com>; 'pgsql-sql@hub.org' <pgsql-sql@hub.org>

> I have 96,000 records in a postgres table that has an unpopulated field
> for 
> datetime.  I need the value in that field to be unique, but the ACTUAL 
> value isn't really that important.  I'd like to begin with the first 
> record, enter a date and time, and then increment that value by one second
> 
> for the next field, one second for the next, and so on.  Can I do this 
> directly from within psql??  I could do this in dbase w/ no problem, but 
> I'm really not that familiar with sql syntax. . .
> 
> jt
> 
You might be able to do it with a creative use of a sequence.

create sequence my_seq;
create table test ( my_d datetime PRIMARY KEY DEFAULT
now()+(nextval('my_seq') || ' seconds'), ...)

You still have problems with duplicates happening as in my reply to your
othe message.
you can take the default (now()+(nextval('my_seq') || ' seconds')) and use
it in an INSERT statement to the same effect.

	-DEJ





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* RE: [SQL] incrementing by the second
@ 1999-04-27 21:16  JT Kirkpatrick <jt-kirkpatrick@mpsllc.com>
  0 siblings, 0 replies; 3+ messages in thread

From: JT Kirkpatrick @ 1999-04-27 21:16 UTC (permalink / raw)
  To: 'Jackson, DeJuan' <djackson@cpsgroup.com>; 'pgsql-sql@hub.org' <pgsql-sql@hub.org>

That worked "mahvelous" - thanks much!  No duplicate values!

jt

-----Original Message-----
From:	Jackson, DeJuan [SMTP:djackson@cpsgroup.com]
Sent:	Tuesday, April 27, 1999 4:42 PM
To:	JT Kirkpatrick; 'pgsql-sql@hub.org'
Subject:	RE: [SQL] incrementing by the second

> I have 96,000 records in a postgres table that has an unpopulated field
> for 
> datetime.  I need the value in that field to be unique, but the ACTUAL 
> value isn't really that important.  I'd like to begin with the first 
> record, enter a date and time, and then increment that value by one second
> 
> for the next field, one second for the next, and so on.  Can I do this 
> directly from within psql??  I could do this in dbase w/ no problem, but 
> I'm really not that familiar with sql syntax. . .
> 
> jt
> 
You might be able to do it with a creative use of a sequence.

create sequence my_seq;
create table test ( my_d datetime PRIMARY KEY DEFAULT
now()+(nextval('my_seq') || ' seconds'), ...)

You still have problems with duplicates happening as in my reply to your
othe message.
you can take the default (now()+(nextval('my_seq') || ' seconds')) and use
it in an INSERT statement to the same effect.

	-DEJ




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~1999-04-27 21:16 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-04-27 20:13 incrementing by the second JT Kirkpatrick <jt-kirkpatrick@mpsllc.com>
1999-04-27 20:41 RE: [SQL] incrementing by the second Jackson, DeJuan <djackson@cpsgroup.com>
1999-04-27 21:16 RE: [SQL] incrementing by the second JT Kirkpatrick <jt-kirkpatrick@mpsllc.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox