MySQL Forums :: Newbie :: UNIX_TIMESTAMP Duplicate key


Advanced Search

UNIX_TIMESTAMP Duplicate key
Posted by: Martin Beaudet ()
Date: January 08, 2010 07:48PM

Hi,

I need to make a stress test on my database.

To do this, I made a program in C #. NET that injects a line by 5 minutes and for a duration of 4 years. Let's say between 2006 and 2010.

My table consists of 2 fields, a date and a value.

The date is now DATETIME type and it is the primary key of the table.

But I want to convert it to INT UNSIGNED format to store a UNIX_TIMESTAMP because I do a lot of operation on time.

In short, with the DATETIME field, 4 years of data's insertion perfectly with the C# test program.

Exemple of injection :
INSERT INTO myTable (sv_Date, sv_Value)
   VALUE ('2006-01-01 00:00:00', 10.0),
   VALUE ('2006-01-01 00:05:00', 80.0)
    ...
When I try with an INT field, I get several duplicates.

Exemple of injection :
INSERT INTO myTable (sv_Date, sv_Value)
   VALUE (UNIXTIME_STAMP ('2006-12-03 00:00:00'), 10.0)
   VALUE (UNIXTIME_STAMP ('2006-12-03 00:05:00'), 80.0)
   ...
Yet when the date field is DATETIME it works well! So why when the field type is an INT UNSIGNED fill with UNIX_TIMESTAMP() it does not work ?

I do not understand the problem ...

I decied to add one more field to my table. sv_RealDate of type DateTime. Now the C# program will insert data as :
INSERT INTO myTable (sv_Date, sv_Value, sv_RealDate)
   VALUE (UNIXTIME_STAMP ('2006-12-03 00:00:00'), 10.0, '2006-12-03 00:00:00')
   VALUE (UNIXTIME_STAMP ('2006-12-03 00:05:00'), 80.0, '2006-12-03 00:05:00')
   ...

Here is a sample output of what I've found on my table using this query :
SELECT sv_Date,
       sv_Value,
       sv_RealDate,
       FROM_UNIXTIME(sv_Date)
FROM SensorsValues
WHERE sv_Date = UNIX_TIMESTAMP('2006-03-12 02:00:00')

  sv_Date    sv_Value       sv_RealDate        sv_RealDateToUnixTime
1142146800, -92.35,    '2006-03-12 02:00:00', '2006-03-12 03:00:00'
1142146800, -76.58,    '2006-03-12 02:05:00', '2006-03-12 03:00:00'
1142146800, -86.05,    '2006-03-12 02:10:00', '2006-03-12 03:00:00'
1142146800,  17.91,    '2006-03-12 02:15:00', '2006-03-12 03:00:00'

Column "sv_RealDateTimeToUnixTime" should have the same value has "sv_RealDate" but at my surprise no ! Why ? DST maybe ?

I would like to simply insert and retrieve a date value without worrying about the DST or timezone. It is possible using UNIX TIMESTAMP ?

Someone have an idea ?
Best regards



Edited 3 time(s). Last edit at 01/09/2010 10:12AM by Martin Beaudet.

Options: ReplyQuote


Subject Written By Posted
UNIX_TIMESTAMP Duplicate key Martin Beaudet 01/08/2010 07:48PM
Re: UNIX_TIMESTAMP Duplicate key Martin Beaudet 01/09/2010 10:23AM
Re: UNIX_TIMESTAMP Duplicate key Rick James 01/10/2010 03:57PM
Re: UNIX_TIMESTAMP Duplicate key Martin Beaudet 01/10/2010 05:24PM
Re: UNIX_TIMESTAMP Duplicate key Rick James 01/11/2010 01:31AM
Re: UNIX_TIMESTAMP Duplicate key Martin Beaudet 01/11/2010 10:23AM
Re: UNIX_TIMESTAMP Duplicate key Rick James 01/11/2010 11:26PM
Re: UNIX_TIMESTAMP Duplicate key Martin Beaudet 01/12/2010 07:01PM
Re: UNIX_TIMESTAMP Duplicate key Rick James 01/12/2010 11:37PM
Re: UNIX_TIMESTAMP Duplicate key Martin Beaudet 01/13/2010 07:08AM
Re: UNIX_TIMESTAMP Duplicate key Rick James 01/13/2010 09:32AM
Re: UNIX_TIMESTAMP Duplicate key Martin Beaudet 01/13/2010 10:45AM
Re: UNIX_TIMESTAMP Duplicate key Rick James 01/13/2010 09:08PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.