pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
default timestamp in postresql
5+ messages / 4 participants
[nested] [flat]

* default timestamp in postresql
@ 2004-07-29 07:16 azah azah <izza76@gmail.com>
  2004-07-29 07:22 ` Re: default timestamp in postresql Michael Glaesemann <grzm@myrealbox.com>
  2004-07-29 07:30 ` Re: default timestamp in postresql Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2004-07-29 10:01 ` Re: default timestamp in postresql Scott Marlowe <smarlowe@qwest.net>
  0 siblings, 3 replies; 5+ messages in thread

From: azah azah @ 2004-07-29 07:16 UTC (permalink / raw)
  To: pgsql-php

Hi, 
I need some help to solve a problem regarding transfer the db from
mysql to postresql.
Previously in mysql table field as below , will be add automatic in
database when execute insert statement.

             = submittime timestamp NOT NULL

But in postresql the timestamp cannot insert automatic when execute
insert statement.
How can I solve this problem instead of change the php code?



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

* Re: default timestamp in postresql
  2004-07-29 07:16 default timestamp in postresql azah azah <izza76@gmail.com>
@ 2004-07-29 07:22 ` Michael Glaesemann <grzm@myrealbox.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Michael Glaesemann @ 2004-07-29 07:22 UTC (permalink / raw)
  To: azah azah <izza76@gmail.com>; +Cc: pgsql-php


On Jul 29, 2004, at 4:16 PM, azah azah wrote:

> Previously in mysql table field as below , will be add automatic in
> database when execute insert statement.
>
>              = submittime timestamp NOT NULL

subttime timestamp NOT NULL DEFAULT now()

Michael Glaesemann
grzm myrealbox com




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

* Re: default timestamp in postresql
  2004-07-29 07:16 default timestamp in postresql azah azah <izza76@gmail.com>
@ 2004-07-29 07:30 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2004-07-29 07:58   ` Re: default timestamp in postresql azah azah <izza76@gmail.com>
  2 siblings, 1 reply; 5+ messages in thread

From: Christopher Kings-Lynne @ 2004-07-29 07:30 UTC (permalink / raw)
  To: azah azah <izza76@gmail.com>; +Cc: pgsql-php

> Previously in mysql table field as below , will be add automatic in
> database when execute insert statement.
> 
>              = submittime timestamp NOT NULL
> 
> But in postresql the timestamp cannot insert automatic when execute
> insert statement.
> How can I solve this problem instead of change the php code?

Make it:

submittime timestamp not null default current_timestamp

Chris




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

* Re: default timestamp in postresql
  2004-07-29 07:16 default timestamp in postresql azah azah <izza76@gmail.com>
  2004-07-29 07:30 ` Re: default timestamp in postresql Christopher Kings-Lynne <chriskl@familyhealth.com.au>
@ 2004-07-29 07:58   ` azah azah <izza76@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: azah azah @ 2004-07-29 07:58 UTC (permalink / raw)
  To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: pgsql-php

thanks all, it solve now.

On Thu, 29 Jul 2004 15:30:59 +0800, Christopher Kings-Lynne
<chriskl@familyhealth.com.au> wrote:
> > Previously in mysql table field as below , will be add automatic in
> > database when execute insert statement.
> >
> >              = submittime timestamp NOT NULL
> >
> > But in postresql the timestamp cannot insert automatic when execute
> > insert statement.
> > How can I solve this problem instead of change the php code?
> 
> Make it:
> 
> submittime timestamp not null default current_timestamp
> 
> Chris
> 
>



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

* Re: default timestamp in postresql
  2004-07-29 07:16 default timestamp in postresql azah azah <izza76@gmail.com>
@ 2004-07-29 10:01 ` Scott Marlowe <smarlowe@qwest.net>
  2 siblings, 0 replies; 5+ messages in thread

From: Scott Marlowe @ 2004-07-29 10:01 UTC (permalink / raw)
  To: azah azah <izza76@gmail.com>; +Cc: pgsql-php

On Thu, 2004-07-29 at 01:16, azah azah wrote:
> Hi, 
> I need some help to solve a problem regarding transfer the db from
> mysql to postresql.
> Previously in mysql table field as below , will be add automatic in
> database when execute insert statement.
> 
>              = submittime timestamp NOT NULL
> 
> But in postresql the timestamp cannot insert automatic when execute
> insert statement.
> How can I solve this problem instead of change the php code?

If you need that field to always be updated whenever the row is changed,
you can use a trigger.

-- FUNCTION --

CREATE FUNCTION modtime () RETURNS opaque AS '
    BEGIN
        new.lm :=''now'';
        RETURN new;
    END;
' LANGUAGE 'plpgsql';

-- TABLE --

CREATE TABLE dtest (
    id int primary key,
    fluff text,
    lm timestamp without time zone
);


--TRIGGER --

CREATE TRIGGER dtest 
  BEFORE UPDATE or INSERT ON dtest FOR EACH ROW EXECUTE PROCEDURE
    modtime(lm);

-- SQL TESTS --

INSERT INTO dtest (id, fluff) VALUES (1,'this is a test');
INSERT INTO dtest (id, fluff) VALUES (2,'this is another test');
SELECT * FROM dtest;
  1 | this is a test       | 2003-04-02 10:33:12.577089
  2 | this is another test | 2003-04-02 10:33:18.591148
UPDATE dtest SET id=3 WHERE id=1;
  3 | this is a test | 2003-04-02 10:34:52.219963  [1]
UPDATE dtest SET fluff='now is the time' WHERE id=2;
SELECT * FROM dtest WHERE id=2;
  2 | now is the time | 2003-04-02 10:38:06.259443 [2]
UPDATE dtest SET lm='2003-04-02 08:30:00' WHERE id=3;
SELECT * FROM dtest WHERE id=3;
  3 | this is a test | 2003-04-02 10:36:15.45687 [3]

[1] The timestamp has changed for this record when we changed the id field.
[2] The timestamp also changes for the fluff field.
[3] We tried to set lm, but the trigger on that field in dtest intercepted the change and forced it 





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


end of thread, other threads:[~2004-07-29 10:01 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-07-29 07:16 default timestamp in postresql azah azah <izza76@gmail.com>
2004-07-29 07:22 ` Michael Glaesemann <grzm@myrealbox.com>
2004-07-29 07:30 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2004-07-29 07:58   ` azah azah <izza76@gmail.com>
2004-07-29 10:01 ` Scott Marlowe <smarlowe@qwest.net>

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