pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jackson, DeJuan <djackson@cpsgroup.com>
To: JT Kirkpatrick <jt-kirkpatrick@mpsllc.com>
To: 'pgsql-sql@hub.org' <pgsql-sql@hub.org>
Subject: RE: [SQL] incrementing by the second
Date: Tue, 27 Apr 1999 15:41:39 -0500
Message-ID: <D05EF808F2DFD211AE4A00105AA1B5D20DCC2F@cpsmail> (raw)

> 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





view thread (3+ messages)  latest in thread

Message-ID: <D05EF808F2DFD211AE4A00105AA1B5D20DCC2F@cpsmail>
Permalink:  ../D05EF808F2DFD211AE4A00105AA1B5D20DCC2F@cpsmail/
Also on:    postgresql.org/message-id/D05EF808F2DFD211AE4A00105AA1B5D20DCC2F@cpsmail

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: djackson@cpsgroup.com, jt-kirkpatrick@mpsllc.com, pgsql-sql@hub.org
  Subject: Re: [SQL] incrementing by the second
  In-Reply-To: <D05EF808F2DFD211AE4A00105AA1B5D20DCC2F@cpsmail>
  References: <D05EF808F2DFD211AE4A00105AA1B5D20DCC2F@cpsmail>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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