in reply to Cleaning Up Apache::Session data

Directly from the mySQL docs:

6.2.2.2 The DATETIME, DATE, and TIMESTAMP Types

The DATETIME, DATE, and TIMESTAMP types are related. This section describes their characteristics, how they are similar, and how they differ.

The DATETIME type is used when you need values that contain both date and time information. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. (``Supported'' means that although earlier values might work, there is no guarantee that they will.)

The DATE type is used when you need only a date value, without a time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.

The TIMESTAMP column type provides a type that you can use to automatically mark INSERT or UPDATE operations with the current date and time. If you have multiple TIMESTAMP columns, only the first one is updated automatically.

Automatic updating of the first TIMESTAMP column occurs under any of the following conditions:

You can set any TIMESTAMP column to a value different from the current date and time by setting it explicitly to the desired value. This is true even for the first TIMESTAMP column. You can use this property if, for example, you want a TIMESTAMP to be set to the current date and time when you create a row, but not to be changed whenever the row is updated later:

Let MySQL set the column when the row is created. This will initialise it to the current date and time.

When you perform subsequent updates to other columns in the row, set the TIMESTAMP column explicitly to its current value.

On the other hand, you may find it just as easy to use a DATETIME column that you initialise to NOW() when the row is created and leave alone for subsequent updates.

Update: As hardburn pointed out, the original poster is using PostgreSQL. STill, nice to see that mySQL has some functionality which is lacking in PostgreSQL ;-)

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re: Re: Cleaning Up Apache::Session data
by hardburn (Abbot) on Mar 31, 2003 at 15:19 UTC

    The orginal poster is using PostgreSQL. I don't use PostgreSQL much, but I did a quick scan over thier docs. PostgreSQL doesn't appear to have the same autmatic TIMESTAMP updates that MySQL has. Someone more familer with PostgreSQL will have to verify this for me, though.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

      PostgreSQL has triggers. You can implement the same functionality with a simple BEFORE UPDATE/INSERT trigger.

      90% of every Perl application is already written.
      dragonchild

      PostgreSQL allows setting of a default value for a column, triggers are not needed for this task. See my reply to another node in this thread at Re: Re: Cleaning Up Apache::Session data.

      Update: Triggers are what's desired here since he wants to update the rows ald set the time also.