pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedTimestamp of insertion of the row.
13+ messages / 6 participants
[nested] [flat]
* Timestamp of insertion of the row.
@ 2003-06-11 09:12 Anagha Joshi <ajoshi@nulinkinc.com>
2003-06-11 09:32 ` Re: Timestamp of insertion of the row. Peter Galbavy <peter.galbavy@knowtion.net>
2003-06-11 09:58 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
2003-06-11 14:16 ` Re: Timestamp of insertion of the row. A.Bhuvaneswaran <bhuvan@symonds.net>
2003-06-12 12:00 ` Re: Timestamp of insertion of the row. Henry House <hajhouse@houseag.uce-not-wanted-here.com>
0 siblings, 4 replies; 13+ messages in thread
From: Anagha Joshi @ 2003-06-11 09:12 UTC (permalink / raw)
To: pgsql-admin
Hi,
Is there any way to know data & time when the row is inserted into a
table?
Help appreciated.
Thx,
Anagha
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
@ 2003-06-11 09:32 ` Peter Galbavy <peter.galbavy@knowtion.net>
3 siblings, 0 replies; 13+ messages in thread
From: Peter Galbavy @ 2003-06-11 09:32 UTC (permalink / raw)
To: Anagha Joshi <ajoshi@nulinkinc.com>; pgsql-admin
Anagha Joshi wrote:
> Hi,
> Is there any way to know data & time when the row is inserted into a
> table?
A timestamp column with a default value of 'now' ???
This will only work for inserts and not updates.
Peter
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
@ 2003-06-11 09:58 ` Mendola Gaetano <mendola@bigfoot.com>
3 siblings, 0 replies; 13+ messages in thread
From: Mendola Gaetano @ 2003-06-11 09:58 UTC (permalink / raw)
To: Anagha Joshi <ajoshi@nulinkinc.com>; pgsql-admin
"Anagha Joshi" <ajoshi@nulinkinc.com> wrote:
> Hi,
> Is there any way to know data & time when the row is inserted into a
> table?
You should define a supplementary field with default value "now()"
this field will contain the transaction start time, if you want have the
real time (if you insert a milion of row inside the same transaction
using now() you'll have the same timestamp ) you should use instead:
"timeofday()".
Regards
Gaetano Mendola
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
@ 2003-06-11 14:16 ` A.Bhuvaneswaran <bhuvan@symonds.net>
3 siblings, 0 replies; 13+ messages in thread
From: A.Bhuvaneswaran @ 2003-06-11 14:16 UTC (permalink / raw)
To: Anagha Joshi <ajoshi@nulinkinc.com>; +Cc: pgsql-admin
> Hi,
> Is there any way to know data & time when the row is inserted into a
> table?
Add a timestamp field and set the default value as now(). If you wish to
maintain similar value during update, a before trigger could help.
regards,
bhuvaneswaran
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
@ 2003-06-12 12:00 ` Henry House <hajhouse@houseag.uce-not-wanted-here.com>
2003-06-12 22:17 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
3 siblings, 1 reply; 13+ messages in thread
From: Henry House @ 2003-06-12 12:00 UTC (permalink / raw)
To: Anagha Joshi <ajoshi@nulinkinc.com>; +Cc: pgsql-admin
On Wed, Jun 11, 2003 at 02:42:42PM +0530, Anagha Joshi wrote:
> Hi,
> Is there any way to know data & time when the row is inserted into a
> table?
Yes. Easy answer: use a column of type 'timestamp default now()'. Whenever
row is inserted with the value for that columns unspecified, it will take on
the current timestamp. Harder answer: write a function to update the
timestamp columns and run before update or insert as a trigger on the table
in question. Here is working example:
CREATE TABLE "example" (
"id" integer DEFAULT nextval('"example_id_seq"'::text) NOT NULL,
"descr" text,
"mod" timestamp with time zone DEFAULT now(),
"last_user" text,
Constraint "example_pkey" Primary Key ("id")
);
CREATE OR REPLACE FUNCTION "update_example_timestamp" () RETURNS opaque AS '
BEGIN
-- Remember who last changed the row and when
NEW.mod := ''now'';
NEW.last_user := current_user;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
CREATE TRIGGER "example_on_update_set_timestamp" BEFORE INSERT OR UPDATE ON "example" FOR EACH ROW EXECUTE PROCEDURE "update_example_timestamp" ();
This also logs the last user to modify the row. This system provides only
rudimentary accountability; a more rigorous solution would be to log all
inserts and updates to a row in another table example_log with columns for
example id, timestamp, and user.
PS. On most public lists, HTML e-mail is considered improper. It will also
cause people who filter HTML e-mail as spam to likely not see your messages.
I recommend sending plain text e-mail only to public mailing lists.
--
Henry House
The attached file is a digital signature. See <http://romana.hajhouse.org/pgp;
for information. My OpenPGP key: <http://romana.hajhouse.org/hajhouse.asc;.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
2003-06-12 12:00 ` Re: Timestamp of insertion of the row. Henry House <hajhouse@houseag.uce-not-wanted-here.com>
@ 2003-06-12 22:17 ` Mendola Gaetano <mendola@bigfoot.com>
2003-06-13 15:39 ` Re: Timestamp of insertion of the row. Bruno Wolff III <bruno@wolff.to>
0 siblings, 1 reply; 13+ messages in thread
From: Mendola Gaetano @ 2003-06-12 22:17 UTC (permalink / raw)
To: Henry House <hajhouse@houseag.uce-not-wanted-here.com>; Anagha Joshi <ajoshi@nulinkinc.com>; +Cc: pgsql-admin
"Henry House" <hajhouse@houseag.uce-not-wanted-here.com> wrote:
> Yes. Easy answer: use a column of type 'timestamp default now()'.
With that default value you store the time
stamp of transaction where the row was inserted. Immagine to insert
inside the same transaction a lot of rows and this operation will take long
1 minute, you'll have all rows with the same time stamp instead of time
stamp spreaded inside that minute, use timeofday instead.
Regards
Gaetano Mendola
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
2003-06-12 12:00 ` Re: Timestamp of insertion of the row. Henry House <hajhouse@houseag.uce-not-wanted-here.com>
2003-06-12 22:17 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
@ 2003-06-13 15:39 ` Bruno Wolff III <bruno@wolff.to>
2003-06-16 08:34 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
0 siblings, 1 reply; 13+ messages in thread
From: Bruno Wolff III @ 2003-06-13 15:39 UTC (permalink / raw)
To: Mendola Gaetano <mendola@bigfoot.com>; +Cc: Henry House <hajhouse@houseag.uce-not-wanted-here.com>; Anagha Joshi <ajoshi@nulinkinc.com>; pgsql-admin
On Fri, Jun 13, 2003 at 00:17:38 +0200,
Mendola Gaetano <mendola@bigfoot.com> wrote:
> "Henry House" <hajhouse@houseag.uce-not-wanted-here.com> wrote:
> > Yes. Easy answer: use a column of type 'timestamp default now()'.
>
> With that default value you store the time
> stamp of transaction where the row was inserted. Immagine to insert
> inside the same transaction a lot of rows and this operation will take long
> 1 minute, you'll have all rows with the same time stamp instead of time
> stamp spreaded inside that minute, use timeofday instead.
You still may not want to use timeofday even for long transactions.
It depends on what the data really means to you.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
2003-06-12 12:00 ` Re: Timestamp of insertion of the row. Henry House <hajhouse@houseag.uce-not-wanted-here.com>
2003-06-12 22:17 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
2003-06-13 15:39 ` Re: Timestamp of insertion of the row. Bruno Wolff III <bruno@wolff.to>
@ 2003-06-16 08:34 ` Mendola Gaetano <mendola@bigfoot.com>
2003-06-16 10:07 ` Re: Timestamp of insertion of the row. Bruno Wolff III <bruno@wolff.to>
0 siblings, 1 reply; 13+ messages in thread
From: Mendola Gaetano @ 2003-06-16 08:34 UTC (permalink / raw)
To: Bruno Wolff III <bruno@wolff.to>; +Cc: Henry House <hajhouse@houseag.uce-not-wanted-here.com>; Anagha Joshi <ajoshi@nulinkinc.com>; pgsql-admin
"Bruno Wolff III" <bruno@wolff.to> wrote:
> You still may not want to use timeofday even for long transactions.
> It depends on what the data really means to you.
The OP was looking for a way to know the time of a row insertion,
not the time of the transaction inside where the row was inserted.
Regards
Gaetano Mendola
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
2003-06-12 12:00 ` Re: Timestamp of insertion of the row. Henry House <hajhouse@houseag.uce-not-wanted-here.com>
2003-06-12 22:17 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
2003-06-13 15:39 ` Re: Timestamp of insertion of the row. Bruno Wolff III <bruno@wolff.to>
2003-06-16 08:34 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
@ 2003-06-16 10:07 ` Bruno Wolff III <bruno@wolff.to>
2003-06-16 10:12 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
0 siblings, 1 reply; 13+ messages in thread
From: Bruno Wolff III @ 2003-06-16 10:07 UTC (permalink / raw)
To: Mendola Gaetano <mendola@bigfoot.com>; +Cc: Henry House <hajhouse@houseag.uce-not-wanted-here.com>; Anagha Joshi <ajoshi@nulinkinc.com>; pgsql-admin
On Mon, Jun 16, 2003 at 10:34:46 +0200,
Mendola Gaetano <mendola@bigfoot.com> wrote:
> "Bruno Wolff III" <bruno@wolff.to> wrote:
> > You still may not want to use timeofday even for long transactions.
> > It depends on what the data really means to you.
>
> The OP was looking for a way to know the time of a row insertion,
> not the time of the transaction inside where the row was inserted.
And what exactly does that mean? My point was that there are a number
of different things this could mean. Once that question is answered
then it is possibl to give more precise solutions to the problem.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
2003-06-12 12:00 ` Re: Timestamp of insertion of the row. Henry House <hajhouse@houseag.uce-not-wanted-here.com>
2003-06-12 22:17 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
2003-06-13 15:39 ` Re: Timestamp of insertion of the row. Bruno Wolff III <bruno@wolff.to>
2003-06-16 08:34 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
2003-06-16 10:07 ` Re: Timestamp of insertion of the row. Bruno Wolff III <bruno@wolff.to>
@ 2003-06-16 10:12 ` Mendola Gaetano <mendola@bigfoot.com>
0 siblings, 0 replies; 13+ messages in thread
From: Mendola Gaetano @ 2003-06-16 10:12 UTC (permalink / raw)
To: Bruno Wolff III <bruno@wolff.to>; +Cc: Henry House <hajhouse@houseag.uce-not-wanted-here.com>; Anagha Joshi <ajoshi@nulinkinc.com>; pgsql-admin
"Bruno Wolff III" <bruno@wolff.to> wrote:
> Mendola Gaetano <mendola@bigfoot.com> wrote:
> > "Bruno Wolff III" <bruno@wolff.to> wrote:
> > > You still may not want to use timeofday even for long transactions.
> > > It depends on what the data really means to you.
> >
> > The OP was looking for a way to know the time of a row insertion,
> > not the time of the transaction inside where the row was inserted.
>
> And what exactly does that mean? My point was that there are a number
> of different things this could mean. Once that question is answered
> then it is possibl to give more precise solutions to the problem.
I totally agree with you.
Gaetano
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
@ 2003-06-16 10:15 Anagha Joshi <ajoshi@nulinkinc.com>
2003-06-16 10:56 ` Re: Timestamp of insertion of the row. Mendola Gaetano <mendola@bigfoot.com>
2003-06-16 11:46 ` Re: Timestamp of insertion of the row. Bruno Wolff III <bruno@wolff.to>
0 siblings, 2 replies; 13+ messages in thread
From: Anagha Joshi @ 2003-06-16 10:15 UTC (permalink / raw)
To: Mendola Gaetano <mendola@bigfoot.com>; +Cc: pgsql-admin
Hi All,
I mean to say ....
Can I know the time when particular row is inserted into the table? i.e.
timestamp of insertion of row into the table.
Pls. note this.
Thx,
Anagha
-----Original Message-----
From: Mendola Gaetano [mailto:mendola@bigfoot.com]
Sent: Monday, June 16, 2003 2:05 PM
To: Bruno Wolff III
Cc: Henry House; Anagha Joshi; pgsql-admin@postgresql.org
Subject: Re: [ADMIN] Timestamp of insertion of the row.
"Bruno Wolff III" <bruno@wolff.to> wrote:
> You still may not want to use timeofday even for long transactions.
> It depends on what the data really means to you.
The OP was looking for a way to know the time of a row insertion,
not the time of the transaction inside where the row was inserted.
Regards
Gaetano Mendola
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-16 10:15 Re: Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
@ 2003-06-16 10:56 ` Mendola Gaetano <mendola@bigfoot.com>
1 sibling, 0 replies; 13+ messages in thread
From: Mendola Gaetano @ 2003-06-16 10:56 UTC (permalink / raw)
To: Anagha Joshi <ajoshi@nulinkinc.com>; +Cc: pgsql-admin
"Anagha Joshi" <ajoshi@nulinkinc.com> wrote:
> Hi All,
> I mean to say ....
> Can I know the time when particular row is inserted into the table? i.e.
> timestamp of insertion of row into the table.
Is not clear what you want:
# begin transaction; // 10:00:00 AM
[ 3 minutes of delay ( computation, others rows inserted, ... ]
# insert row // 10:03:00 AM
# end transaction;
if you use default now() you will have on the time stamp: 10:00:00 AM
if you use default timeofday() you will have on the time stamp: 10:03:00
AM
regards
Gaetano Mendola
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Timestamp of insertion of the row.
2003-06-16 10:15 Re: Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
@ 2003-06-16 11:46 ` Bruno Wolff III <bruno@wolff.to>
1 sibling, 0 replies; 13+ messages in thread
From: Bruno Wolff III @ 2003-06-16 11:46 UTC (permalink / raw)
To: Anagha Joshi <ajoshi@nulinkinc.com>; +Cc: Mendola Gaetano <mendola@bigfoot.com>; pgsql-admin
On Mon, Jun 16, 2003 at 15:45:28 +0530,
Anagha Joshi <ajoshi@nulinkinc.com> wrote:
> Hi All,
> I mean to say ....
> Can I know the time when particular row is inserted into the table? i.e.
> timestamp of insertion of row into the table.
That isn't precise. What do you mean when you say it is inserted into the
table. Do you mean when the transaction is committed or started, or perhaps
the time the command to insert the row is run or perhaps the time of the
external event that prompted the the insert? Sometimes these times can
be quite different, especially if you are using persistant connections
with software that issues 'begin's for you.
If the time doesn't need to be synchronized with any other times in the
same transaction, then timeofday is probably your best bet.
^ permalink raw reply [nested|flat] 13+ messages in thread
end of thread, other threads:[~2003-06-16 11:46 UTC | newest]
Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-06-11 09:12 Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
2003-06-11 09:32 ` Peter Galbavy <peter.galbavy@knowtion.net>
2003-06-11 09:58 ` Mendola Gaetano <mendola@bigfoot.com>
2003-06-11 14:16 ` A.Bhuvaneswaran <bhuvan@symonds.net>
2003-06-12 12:00 ` Henry House <hajhouse@houseag.uce-not-wanted-here.com>
2003-06-12 22:17 ` Mendola Gaetano <mendola@bigfoot.com>
2003-06-13 15:39 ` Bruno Wolff III <bruno@wolff.to>
2003-06-16 08:34 ` Mendola Gaetano <mendola@bigfoot.com>
2003-06-16 10:07 ` Bruno Wolff III <bruno@wolff.to>
2003-06-16 10:12 ` Mendola Gaetano <mendola@bigfoot.com>
2003-06-16 10:15 Re: Timestamp of insertion of the row. Anagha Joshi <ajoshi@nulinkinc.com>
2003-06-16 10:56 ` Mendola Gaetano <mendola@bigfoot.com>
2003-06-16 11:46 ` Bruno Wolff III <bruno@wolff.to>
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