PyMySql: SELECT MAX(timestamp) results in “Incorrect datetime value: '0000-00-00 00:00:00'”MySQL Incorrect datetime value: '0000-00-00 00:00:00'Query capturing timestamp 0000-00-00 00:00:00How do you set a default value for a MySQL Datetime column?Should I use the datetime or timestamp data type in MySQL?How can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?'IF' in 'SELECT' statement - choose output value based on column valuesSQL select only rows with max value on a columnMYSQL error with specific timestap valueIncorrect datetime value for column defined as TIMESTAMP in MySQLtrigger default mysql datetime value when not null with php pdohow to skip '' for column? (import excel file python to mysql)MySql deleting rows after a given time. Error 1292 Incorrect datetime value: '1537019628' on a timestamp

How is it possible to have an ability score that is less than 3?

How to efficiently unroll a matrix by value with numpy?

Perform and show arithmetic with LuaLaTeX

Fully-Firstable Anagram Sets

Why do I get two different answers for this counting problem?

How can I make my BBEG immortal short of making them a Lich or Vampire?

How to draw a waving flag in TikZ

Theorems that impeded progress

What typically incentivizes a professor to change jobs to a lower ranking university?

Why doesn't H₄O²⁺ exist?

NMaximize is not converging to a solution

Has there ever been an airliner design involving reducing generator load by installing solar panels?

What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)

Is it unprofessional to ask if a job posting on GlassDoor is real?

How do I deal with an unproductive colleague in a small company?

Is it possible to do 50 km distance without any previous training?

Was any UN Security Council vote triple-vetoed?

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

How to format long polynomial?

Convert two switches to a dual stack, and add outlet - possible here?

Do I have a twin with permutated remainders?

Why is consensus so controversial in Britain?

Replacing matching entries in one column of a file by another column from a different file



PyMySql: SELECT MAX(timestamp) results in “Incorrect datetime value: '0000-00-00 00:00:00'”


MySQL Incorrect datetime value: '0000-00-00 00:00:00'Query capturing timestamp 0000-00-00 00:00:00How do you set a default value for a MySQL Datetime column?Should I use the datetime or timestamp data type in MySQL?How can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?'IF' in 'SELECT' statement - choose output value based on column valuesSQL select only rows with max value on a columnMYSQL error with specific timestap valueIncorrect datetime value for column defined as TIMESTAMP in MySQLtrigger default mysql datetime value when not null with php pdohow to skip '' for column? (import excel file python to mysql)MySql deleting rows after a given time. Error 1292 Incorrect datetime value: '1537019628' on a timestamp






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















I am running a MySQL 5.7 server with two tables:



Table_A



id name
.........
1 foo
2 bar


Table_B



 id parent_id name created_at (default: CURRENT_TIMESTAMP)
................................................................
1 1 x 2019-01-01 10:00:00
2 1 y 2019-12-31 22:00:00


I have this query to get a Table_B entry count grouped by Table_A name with the timestamp of the most recent Table_B entry:



SELECT 
a.name,
COUNT(b.id) AS entry_count_in_b,
MAX(b.created_at) AS last_entry_in_b
FROM
Table_A a
LEFT JOIN
Table_B b ON b.parent_id = a.id
GROUP BY 1


The MySQL command line client returns the expected output:



+------+------------------+---------------------+
| name | entry_count_in_b | last_entry_in_b |
+------+------------------+---------------------+
| bar | 0 | NULL |
| foo | 2 | 2019-12-31 22:00:00 |
+------+------------------+---------------------+
2 rows in set (0.0267 sec)


When I run the same query in Python (3.7) using PyMySql (0.9.3) however, the cursor generates the following warning:



lib/python3.7/site-packages/pymysql/cursors.py:329: Warning: (1292, "Incorrect datetime value: '0000-00-00 00:00:00' for column 'last_entry_in_b' at row 3") 


It might be a bug in PyMySql since the warning is referencing row 3 in a 2 row result set.



Trying to narrow down the root cause, I thought it might have to do with a bug in the aggregation of NULL values in a timestamp column so I updated the query to only calculate MAX(b.created_at) when COUNT(table_b.id) > 1:



SELECT 
a.name,
COUNT(b.id) AS entry_count_in_b,
CASE
WHEN COUNT(b.id) = 0 THEN NULL
ELSE MAX(b.created_at)
END AS last_entry_in_b
FROM
Table_A a
LEFT JOIN
Table_B b ON b.parent_id = a.id
GROUP BY 1


This generates the same warning but now referencing a column named 'tmp_field_0'.



lib/python3.7/site-packages/pymysql/cursors.py:329: Warning: (1292, "Incorrect datetime value: '0000-00-00 00:00:00' for column 'tmp_field_0' at row 3")


I am wondering if anyone has seen / solved this issue before? If not, I will file an issue for PyMySql.



I found other questions discussing this same warning but they cover cases where people try to insert / update '0000-00-00 00:00:00' values or filtering for them.










share|improve this question
























  • You don't need the CASE expression. If there are no rows for a name, MAX(b.created_at) will be NULL automatically. I'm not sure if that will make a difference for PyMySQL, though.

    – Barmar
    Mar 9 at 1:33











  • Correct, that is why it is not in the initial query. I added the CASE expression in the second query because it changes the warning and might help identify the root cause.

    – Stipy
    Mar 9 at 1:35












  • Seems like a bug in PyMySQL. It's getting the type of the column, and not dealing with null values properly.

    – Barmar
    Mar 9 at 20:40

















3















I am running a MySQL 5.7 server with two tables:



Table_A



id name
.........
1 foo
2 bar


Table_B



 id parent_id name created_at (default: CURRENT_TIMESTAMP)
................................................................
1 1 x 2019-01-01 10:00:00
2 1 y 2019-12-31 22:00:00


I have this query to get a Table_B entry count grouped by Table_A name with the timestamp of the most recent Table_B entry:



SELECT 
a.name,
COUNT(b.id) AS entry_count_in_b,
MAX(b.created_at) AS last_entry_in_b
FROM
Table_A a
LEFT JOIN
Table_B b ON b.parent_id = a.id
GROUP BY 1


The MySQL command line client returns the expected output:



+------+------------------+---------------------+
| name | entry_count_in_b | last_entry_in_b |
+------+------------------+---------------------+
| bar | 0 | NULL |
| foo | 2 | 2019-12-31 22:00:00 |
+------+------------------+---------------------+
2 rows in set (0.0267 sec)


When I run the same query in Python (3.7) using PyMySql (0.9.3) however, the cursor generates the following warning:



lib/python3.7/site-packages/pymysql/cursors.py:329: Warning: (1292, "Incorrect datetime value: '0000-00-00 00:00:00' for column 'last_entry_in_b' at row 3") 


It might be a bug in PyMySql since the warning is referencing row 3 in a 2 row result set.



Trying to narrow down the root cause, I thought it might have to do with a bug in the aggregation of NULL values in a timestamp column so I updated the query to only calculate MAX(b.created_at) when COUNT(table_b.id) > 1:



SELECT 
a.name,
COUNT(b.id) AS entry_count_in_b,
CASE
WHEN COUNT(b.id) = 0 THEN NULL
ELSE MAX(b.created_at)
END AS last_entry_in_b
FROM
Table_A a
LEFT JOIN
Table_B b ON b.parent_id = a.id
GROUP BY 1


This generates the same warning but now referencing a column named 'tmp_field_0'.



lib/python3.7/site-packages/pymysql/cursors.py:329: Warning: (1292, "Incorrect datetime value: '0000-00-00 00:00:00' for column 'tmp_field_0' at row 3")


I am wondering if anyone has seen / solved this issue before? If not, I will file an issue for PyMySql.



I found other questions discussing this same warning but they cover cases where people try to insert / update '0000-00-00 00:00:00' values or filtering for them.










share|improve this question
























  • You don't need the CASE expression. If there are no rows for a name, MAX(b.created_at) will be NULL automatically. I'm not sure if that will make a difference for PyMySQL, though.

    – Barmar
    Mar 9 at 1:33











  • Correct, that is why it is not in the initial query. I added the CASE expression in the second query because it changes the warning and might help identify the root cause.

    – Stipy
    Mar 9 at 1:35












  • Seems like a bug in PyMySQL. It's getting the type of the column, and not dealing with null values properly.

    – Barmar
    Mar 9 at 20:40













3












3








3


0






I am running a MySQL 5.7 server with two tables:



Table_A



id name
.........
1 foo
2 bar


Table_B



 id parent_id name created_at (default: CURRENT_TIMESTAMP)
................................................................
1 1 x 2019-01-01 10:00:00
2 1 y 2019-12-31 22:00:00


I have this query to get a Table_B entry count grouped by Table_A name with the timestamp of the most recent Table_B entry:



SELECT 
a.name,
COUNT(b.id) AS entry_count_in_b,
MAX(b.created_at) AS last_entry_in_b
FROM
Table_A a
LEFT JOIN
Table_B b ON b.parent_id = a.id
GROUP BY 1


The MySQL command line client returns the expected output:



+------+------------------+---------------------+
| name | entry_count_in_b | last_entry_in_b |
+------+------------------+---------------------+
| bar | 0 | NULL |
| foo | 2 | 2019-12-31 22:00:00 |
+------+------------------+---------------------+
2 rows in set (0.0267 sec)


When I run the same query in Python (3.7) using PyMySql (0.9.3) however, the cursor generates the following warning:



lib/python3.7/site-packages/pymysql/cursors.py:329: Warning: (1292, "Incorrect datetime value: '0000-00-00 00:00:00' for column 'last_entry_in_b' at row 3") 


It might be a bug in PyMySql since the warning is referencing row 3 in a 2 row result set.



Trying to narrow down the root cause, I thought it might have to do with a bug in the aggregation of NULL values in a timestamp column so I updated the query to only calculate MAX(b.created_at) when COUNT(table_b.id) > 1:



SELECT 
a.name,
COUNT(b.id) AS entry_count_in_b,
CASE
WHEN COUNT(b.id) = 0 THEN NULL
ELSE MAX(b.created_at)
END AS last_entry_in_b
FROM
Table_A a
LEFT JOIN
Table_B b ON b.parent_id = a.id
GROUP BY 1


This generates the same warning but now referencing a column named 'tmp_field_0'.



lib/python3.7/site-packages/pymysql/cursors.py:329: Warning: (1292, "Incorrect datetime value: '0000-00-00 00:00:00' for column 'tmp_field_0' at row 3")


I am wondering if anyone has seen / solved this issue before? If not, I will file an issue for PyMySql.



I found other questions discussing this same warning but they cover cases where people try to insert / update '0000-00-00 00:00:00' values or filtering for them.










share|improve this question
















I am running a MySQL 5.7 server with two tables:



Table_A



id name
.........
1 foo
2 bar


Table_B



 id parent_id name created_at (default: CURRENT_TIMESTAMP)
................................................................
1 1 x 2019-01-01 10:00:00
2 1 y 2019-12-31 22:00:00


I have this query to get a Table_B entry count grouped by Table_A name with the timestamp of the most recent Table_B entry:



SELECT 
a.name,
COUNT(b.id) AS entry_count_in_b,
MAX(b.created_at) AS last_entry_in_b
FROM
Table_A a
LEFT JOIN
Table_B b ON b.parent_id = a.id
GROUP BY 1


The MySQL command line client returns the expected output:



+------+------------------+---------------------+
| name | entry_count_in_b | last_entry_in_b |
+------+------------------+---------------------+
| bar | 0 | NULL |
| foo | 2 | 2019-12-31 22:00:00 |
+------+------------------+---------------------+
2 rows in set (0.0267 sec)


When I run the same query in Python (3.7) using PyMySql (0.9.3) however, the cursor generates the following warning:



lib/python3.7/site-packages/pymysql/cursors.py:329: Warning: (1292, "Incorrect datetime value: '0000-00-00 00:00:00' for column 'last_entry_in_b' at row 3") 


It might be a bug in PyMySql since the warning is referencing row 3 in a 2 row result set.



Trying to narrow down the root cause, I thought it might have to do with a bug in the aggregation of NULL values in a timestamp column so I updated the query to only calculate MAX(b.created_at) when COUNT(table_b.id) > 1:



SELECT 
a.name,
COUNT(b.id) AS entry_count_in_b,
CASE
WHEN COUNT(b.id) = 0 THEN NULL
ELSE MAX(b.created_at)
END AS last_entry_in_b
FROM
Table_A a
LEFT JOIN
Table_B b ON b.parent_id = a.id
GROUP BY 1


This generates the same warning but now referencing a column named 'tmp_field_0'.



lib/python3.7/site-packages/pymysql/cursors.py:329: Warning: (1292, "Incorrect datetime value: '0000-00-00 00:00:00' for column 'tmp_field_0' at row 3")


I am wondering if anyone has seen / solved this issue before? If not, I will file an issue for PyMySql.



I found other questions discussing this same warning but they cover cases where people try to insert / update '0000-00-00 00:00:00' values or filtering for them.







mysql mysql-python pymysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 1:45







Stipy

















asked Mar 9 at 1:29









StipyStipy

162




162












  • You don't need the CASE expression. If there are no rows for a name, MAX(b.created_at) will be NULL automatically. I'm not sure if that will make a difference for PyMySQL, though.

    – Barmar
    Mar 9 at 1:33











  • Correct, that is why it is not in the initial query. I added the CASE expression in the second query because it changes the warning and might help identify the root cause.

    – Stipy
    Mar 9 at 1:35












  • Seems like a bug in PyMySQL. It's getting the type of the column, and not dealing with null values properly.

    – Barmar
    Mar 9 at 20:40

















  • You don't need the CASE expression. If there are no rows for a name, MAX(b.created_at) will be NULL automatically. I'm not sure if that will make a difference for PyMySQL, though.

    – Barmar
    Mar 9 at 1:33











  • Correct, that is why it is not in the initial query. I added the CASE expression in the second query because it changes the warning and might help identify the root cause.

    – Stipy
    Mar 9 at 1:35












  • Seems like a bug in PyMySQL. It's getting the type of the column, and not dealing with null values properly.

    – Barmar
    Mar 9 at 20:40
















You don't need the CASE expression. If there are no rows for a name, MAX(b.created_at) will be NULL automatically. I'm not sure if that will make a difference for PyMySQL, though.

– Barmar
Mar 9 at 1:33





You don't need the CASE expression. If there are no rows for a name, MAX(b.created_at) will be NULL automatically. I'm not sure if that will make a difference for PyMySQL, though.

– Barmar
Mar 9 at 1:33













Correct, that is why it is not in the initial query. I added the CASE expression in the second query because it changes the warning and might help identify the root cause.

– Stipy
Mar 9 at 1:35






Correct, that is why it is not in the initial query. I added the CASE expression in the second query because it changes the warning and might help identify the root cause.

– Stipy
Mar 9 at 1:35














Seems like a bug in PyMySQL. It's getting the type of the column, and not dealing with null values properly.

– Barmar
Mar 9 at 20:40





Seems like a bug in PyMySQL. It's getting the type of the column, and not dealing with null values properly.

– Barmar
Mar 9 at 20:40












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073124%2fpymysql-select-maxtimestamp-results-in-incorrect-datetime-value-0000-00-00%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073124%2fpymysql-select-maxtimestamp-results-in-incorrect-datetime-value-0000-00-00%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived