Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2002
    Location
    Toronto
    Posts
    13

    Unanswered: trigger to create timestamp

    <rookie question>

    i have a table with a column;

    joined timestamp not null,

    so... how would i build a trigger that automatically generates a timestamp for column joined?

    something like..

    CREATE TRIGGER trig_person_tstamp
    BEFORE INSERT ON person
    FOR EACH ???????

    what postgres function should i use to get the current timestamp in trig_person_tstamp?

    </rookie question>

    thanks.

  2. #2
    Join Date
    Mar 2002
    Posts
    9

    Thumbs up Re: trigger to create timestamp

    Why don't you define field joined with DEFAULT CURRENT_TIMESTAMP?

    I thing that's you want to do.

    Saludos.


    Originally posted by catch
    <rookie question>

    i have a table with a column;

    joined timestamp not null,

    so... how would i build a trigger that automatically generates a timestamp for column joined?

    something like..

    CREATE TRIGGER trig_person_tstamp
    BEFORE INSERT ON person
    FOR EACH ???????

    what postgres function should i use to get the current timestamp in trig_person_tstamp?

    </rookie question>

    thanks.

  3. #3
    Join Date
    Mar 2002
    Location
    Toronto
    Posts
    13
    thanks.
    what's the syntax for that?

    i found this link on triggers (using a timestamp example).
    which method is more practical?

  4. #4
    Join Date
    Mar 2002
    Posts
    9
    Originally posted by catch
    [B]thanks.
    what's the syntax for that?
    create table xxx
    (
    joined timestamp not null
    defaul current_timestamp
    )

    You can find more information about on "/B]
    create table" syntax


    i found this link on triggers (using a timestamp example).
    which method is more practical?

    the default one, but if it's you want to force the timestamp, i mean, if I wish that the users can't alter the joined's value, you have to use view with roles or table with triggers. And between them, I'd rather use the first methods.

    saludos

  5. #5
    Join Date
    Mar 2002
    Location
    Toronto
    Posts
    13
    thanks uhexo. the default method is what i was loooking for. it works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •