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;
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
add a comment |
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
You don't need theCASE
expression. If there are no rows for a name,MAX(b.created_at)
will beNULL
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 theCASE
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
add a comment |
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
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
mysql mysql-python pymysql
edited Mar 9 at 1:45
Stipy
asked Mar 9 at 1:29
StipyStipy
162
162
You don't need theCASE
expression. If there are no rows for a name,MAX(b.created_at)
will beNULL
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 theCASE
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
add a comment |
You don't need theCASE
expression. If there are no rows for a name,MAX(b.created_at)
will beNULL
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 theCASE
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
You don't need the
CASE
expression. If there are no rows for a name,MAX(b.created_at)
will beNULL
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