Recently, I encountered a database with the following data type: decimal(14,4) The problems encountered are: When I use Python to read data into memory, it always has decimal characters. When I write it into other MySQL tables, the data type is int, which causes data to fail to be stored. import pymysql # Create a database connection con = pymysql.connect() sql = '''select created_time from schma.table LIMIT 10''' try: cur = con.cursor(cursor=pymysql.cursors.DictCursor) cur.execute(sql) except Exception as e: print(e) else: data = cur.fetchall() finally: cur.close() con.close() for d in data: created_time = d.get('created_time') print(created_time) Solution: Use mysql's cast method to convert select cast(created_time as signed) AS created_time from schma.table This is the end of this article about the implementation of MySQL decimal data type conversion. For more information about MySQL decimal data type conversion, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the flexible use of CSS grid system in projects
>>: Implementation of Docker deployment of Nuxt.js project
Table of contents Index Type Index structure Nonc...
I wrote a jsp page today. I tried to adjust <di...
Environment Preparation 1. Environment Constructi...
Div basic layout <div class="main"&g...
Interviewer: Have you read the source code of Vue...
Table of contents 1. Index 1.1 Concept 1.2 Functi...
BMP is an image file format that is independent o...
error message: ERROR 2002 (HY000): Can't conn...
This article example shares the specific code of ...
This article is from Tom Ewer's Managewp blog,...
Table of contents Preface webpack-deb-server webp...
Install First you need to install Java and Scala,...
Table of contents Create an image File Structure ...
Phenomenon There are several nested flex structur...
Preface Workbench is installed on one computer, a...