Unix Technical Forum

Timestamp field ignores supplied value

This is a discussion on Timestamp field ignores supplied value within the MySQL forums, part of the Database Server Software category; --> I'm doing a INSERT...SELECT and one column in the source table is a datetime field with the target column ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:27 AM
Ciaran Byrne
 
Posts: n/a
Default Timestamp field ignores supplied value

I'm doing a INSERT...SELECT and one column in the source table is a
datetime field with the target column being a timestamp format. I'm
changing the format because I can easily switch between timezones with
the latter rather than the former. However, instead of copying the
value from the source column to the target column it inserts the
current date and time. There are 13 million rows but no warnings or
errors are issued.

I've tried it with a small experiment, see below, and it works as
expected. Ideas/solutions welcome.


MySQL> create table tmp (DateTime datetime);
Query OK, 0 rows affected (0.00 sec)

MySQL> create table tmpa (DateTime timestamp);
Query OK, 0 rows affected (0.02 sec)

MySQL> insert into tmp values ("2007-01-01 00:00:00");
Query OK, 1 row affected (0.00 sec)

MySQL> insert into tmp values ("2007-12-25 00:00:00");
Query OK, 1 row affected (0.00 sec)

MySQL> insert into tmp values ("2007-12-26 00:00:00");
Query OK, 1 row affected (0.00 sec)

MySQL> insert into tmp values ("2007-04-01 00:00:00");
Query OK, 1 row affected (0.00 sec)

MySQL> insert into tmp values ("2007-11-05 00:00:00");
Query OK, 1 row affected (0.00 sec)

MySQL> select * from tmp;
+---------------------+
| DateTime |
+---------------------+
| 2007-01-01 00:00:00 |
| 2007-12-25 00:00:00 |
| 2007-12-26 00:00:00 |
| 2007-04-01 00:00:00 |
| 2007-11-05 00:00:00 |
+---------------------+
5 rows in set (0.00 sec)

MySQL> insert into tmpa select * from tmp;
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0

MySQL> select * from tmpa;
+---------------------+
| DateTime |
+---------------------+
| 2007-01-01 00:00:00 |
| 2007-12-25 00:00:00 |
| 2007-12-26 00:00:00 |
| 2007-04-01 00:00:00 |
| 2007-11-05 00:00:00 |
+---------------------+
5 rows in set (0.00 sec)

MySQL> Aborted

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:27 AM
Captain Paralytic
 
Posts: n/a
Default Re: Timestamp field ignores supplied value

On 24 Aug, 10:54, Ciaran Byrne <ciaran.by...@ciaranbyrne.com> wrote:
> I'm doing a INSERT...SELECT and one column in the source table is a
> datetime field with the target column being a timestamp format. I'm
> changing the format because I can easily switch between timezones with
> the latter rather than the former. However, instead of copying the
> value from the source column to the target column it inserts the
> current date and time. There are 13 million rows but no warnings or
> errors are issued.
>
> I've tried it with a small experiment, see below, and it works as
> expected. Ideas/solutions welcome.
>
> MySQL> create table tmp (DateTime datetime);
> Query OK, 0 rows affected (0.00 sec)
>
> MySQL> create table tmpa (DateTime timestamp);
> Query OK, 0 rows affected (0.02 sec)
>
> MySQL> insert into tmp values ("2007-01-01 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> insert into tmp values ("2007-12-25 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> insert into tmp values ("2007-12-26 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> insert into tmp values ("2007-04-01 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> insert into tmp values ("2007-11-05 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> select * from tmp;
> +---------------------+
> | DateTime |
> +---------------------+
> | 2007-01-01 00:00:00 |
> | 2007-12-25 00:00:00 |
> | 2007-12-26 00:00:00 |
> | 2007-04-01 00:00:00 |
> | 2007-11-05 00:00:00 |
> +---------------------+
> 5 rows in set (0.00 sec)
>
> MySQL> insert into tmpa select * from tmp;
> Query OK, 5 rows affected (0.00 sec)
> Records: 5 Duplicates: 0 Warnings: 0
>
> MySQL> select * from tmpa;
> +---------------------+
> | DateTime |
> +---------------------+
> | 2007-01-01 00:00:00 |
> | 2007-12-25 00:00:00 |
> | 2007-12-26 00:00:00 |
> | 2007-04-01 00:00:00 |
> | 2007-11-05 00:00:00 |
> +---------------------+
> 5 rows in set (0.00 sec)
>
> MySQL> Aborted


Your output shows the copies as successful as opposed to having the
current date/time as you say?

How does having the fieldas timestamp rather than datetime help you
with timezones?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:27 AM
Ciaran Byrne
 
Posts: n/a
Default Re: Timestamp field ignores supplied value

On Aug 24, 11:11 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 24 Aug, 10:54, Ciaran Byrne <ciaran.by...@ciaranbyrne.com> wrote:
>
>
>
> > I'm doing a INSERT...SELECT and one column in the source table is a
> > datetime field with the target column being a timestamp format. I'm
> > changing the format because I can easily switch between timezones with
> > the latter rather than the former. However, instead of copying the
> > value from the source column to the target column it inserts the
> > current date and time. There are 13 million rows but no warnings or
> > errors are issued.

>
> > I've tried it with a small experiment, see below, and it works as
> > expected. Ideas/solutions welcome.

>
> > MySQL> create table tmp (DateTime datetime);
> > Query OK, 0 rows affected (0.00 sec)

>
> > MySQL> create table tmpa (DateTime timestamp);
> > Query OK, 0 rows affected (0.02 sec)

>
> > MySQL> insert into tmp values ("2007-01-01 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> insert into tmp values ("2007-12-25 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> insert into tmp values ("2007-12-26 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> insert into tmp values ("2007-04-01 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> insert into tmp values ("2007-11-05 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> select * from tmp;
> > +---------------------+
> > | DateTime |
> > +---------------------+
> > | 2007-01-01 00:00:00 |
> > | 2007-12-25 00:00:00 |
> > | 2007-12-26 00:00:00 |
> > | 2007-04-01 00:00:00 |
> > | 2007-11-05 00:00:00 |
> > +---------------------+
> > 5 rows in set (0.00 sec)

>
> > MySQL> insert into tmpa select * from tmp;
> > Query OK, 5 rows affected (0.00 sec)
> > Records: 5 Duplicates: 0 Warnings: 0

>
> > MySQL> select * from tmpa;
> > +---------------------+
> > | DateTime |
> > +---------------------+
> > | 2007-01-01 00:00:00 |
> > | 2007-12-25 00:00:00 |
> > | 2007-12-26 00:00:00 |
> > | 2007-04-01 00:00:00 |
> > | 2007-11-05 00:00:00 |
> > +---------------------+
> > 5 rows in set (0.00 sec)

>
> > MySQL> Aborted

>
> Your output shows the copies as successful as opposed to having the
> current date/time as you say?


I should have been clearer. The example I gave does work, but the real
statement does not.

>
> How does having the fieldas timestamp rather than datetime help you
> with timezones?


The database always uses UTC so if I run a report based on the date/
time now I'll be one hour out, but if I execute SET TIMEZONE = GB;
then my timezone will become British Summer Time and I can look at
records that occurred at my clock time rather than the stored UTC
time.

HTH

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:27 AM
Captain Paralytic
 
Posts: n/a
Default Re: Timestamp field ignores supplied value

On 24 Aug, 12:39, Ciaran Byrne <ciaran.by...@ciaranbyrne.com> wrote:
> > Your output shows the copies as successful as opposed to having the
> > current date/time as you say?

>
> I should have been clearer. The example I gave does work, but the real
> statement does not.


So you show us something that works and ask us to tell you why
something that you haven't shown us doesn't work!

Well that's clear.

How the H*LL do you expect anyone to help you with that!!!

Hint, maybe posting the stuff that doesn't work might be useful.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:27 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Timestamp field ignores supplied value

Ciaran Byrne wrote:
> I'm doing a INSERT...SELECT and one column in the source table is a
> datetime field with the target column being a timestamp format. I'm
> changing the format because I can easily switch between timezones with
> the latter rather than the former. However, instead of copying the
> value from the source column to the target column it inserts the
> current date and time. There are 13 million rows but no warnings or
> errors are issued.
>
> I've tried it with a small experiment, see below, and it works as
> expected. Ideas/solutions welcome.
>
>
> MySQL> create table tmp (DateTime datetime);
> Query OK, 0 rows affected (0.00 sec)
>
> MySQL> create table tmpa (DateTime timestamp);
> Query OK, 0 rows affected (0.02 sec)
>
> MySQL> insert into tmp values ("2007-01-01 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> insert into tmp values ("2007-12-25 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> insert into tmp values ("2007-12-26 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> insert into tmp values ("2007-04-01 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> insert into tmp values ("2007-11-05 00:00:00");
> Query OK, 1 row affected (0.00 sec)
>
> MySQL> select * from tmp;
> +---------------------+
> | DateTime |
> +---------------------+
> | 2007-01-01 00:00:00 |
> | 2007-12-25 00:00:00 |
> | 2007-12-26 00:00:00 |
> | 2007-04-01 00:00:00 |
> | 2007-11-05 00:00:00 |
> +---------------------+
> 5 rows in set (0.00 sec)
>
> MySQL> insert into tmpa select * from tmp;
> Query OK, 5 rows affected (0.00 sec)
> Records: 5 Duplicates: 0 Warnings: 0
>
> MySQL> select * from tmpa;
> +---------------------+
> | DateTime |
> +---------------------+
> | 2007-01-01 00:00:00 |
> | 2007-12-25 00:00:00 |
> | 2007-12-26 00:00:00 |
> | 2007-04-01 00:00:00 |
> | 2007-11-05 00:00:00 |
> +---------------------+
> 5 rows in set (0.00 sec)
>
> MySQL> Aborted
>


OK, this works as it should. How about showing us the failing tables'
layout and the failing code?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 11:27 AM
Ciaran Byrne
 
Posts: n/a
Default Re: Timestamp field ignores supplied value

On Aug 24, 12:51 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Ciaran Byrne wrote:
> > I'm doing a INSERT...SELECT and one column in the source table is a
> > datetime field with the target column being a timestamp format. I'm
> > changing the format because I can easily switch between timezones with
> > the latter rather than the former. However, instead of copying the
> > value from the source column to the target column it inserts the
> > current date and time. There are 13 million rows but no warnings or
> > errors are issued.

>
> > I've tried it with a small experiment, see below, and it works as
> > expected. Ideas/solutions welcome.

>
> > MySQL> create table tmp (DateTime datetime);
> > Query OK, 0 rows affected (0.00 sec)

>
> > MySQL> create table tmpa (DateTime timestamp);
> > Query OK, 0 rows affected (0.02 sec)

>
> > MySQL> insert into tmp values ("2007-01-01 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> insert into tmp values ("2007-12-25 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> insert into tmp values ("2007-12-26 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> insert into tmp values ("2007-04-01 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> insert into tmp values ("2007-11-05 00:00:00");
> > Query OK, 1 row affected (0.00 sec)

>
> > MySQL> select * from tmp;
> > +---------------------+
> > | DateTime |
> > +---------------------+
> > | 2007-01-01 00:00:00 |
> > | 2007-12-25 00:00:00 |
> > | 2007-12-26 00:00:00 |
> > | 2007-04-01 00:00:00 |
> > | 2007-11-05 00:00:00 |
> > +---------------------+
> > 5 rows in set (0.00 sec)

>
> > MySQL> insert into tmpa select * from tmp;
> > Query OK, 5 rows affected (0.00 sec)
> > Records: 5 Duplicates: 0 Warnings: 0

>
> > MySQL> select * from tmpa;
> > +---------------------+
> > | DateTime |
> > +---------------------+
> > | 2007-01-01 00:00:00 |
> > | 2007-12-25 00:00:00 |
> > | 2007-12-26 00:00:00 |
> > | 2007-04-01 00:00:00 |
> > | 2007-11-05 00:00:00 |
> > +---------------------+
> > 5 rows in set (0.00 sec)

>
> > MySQL> Aborted

>
> OK, this works as it should. How about showing us the failing tables'
> layout and the failing code?
>


I discovered the reason: I was using the table definition from an
earlier mysqldump which changed the definition of the column to be
"DateTime timestamp default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP". Removing the default and on update has fixed the
problem.

Thanks for the replies people.

> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:47 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com