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
echarts component official website address: https...
what is it? GNU Parallel is a shell tool for exec...
Basics In a relational database, each data table ...
Table of contents Preface Background data splicin...
Table of contents need: Problems encountered: sol...
I have been having this problem recently when desi...
Table of contents 1. How the Bootstrap grid syste...
Overlay network analysis Built-in cross-host netw...
Table of contents Listener watch Format Set up th...
1. Computed properties and listeners 1.1 Computed...
Document hints using the show-header attribute sh...
Preface Recently, I encountered a program using S...
1. Download, install and configure mysql-8.0.15 1...
Pseudo-elements and pseudo-classes Speaking of th...
Preface The service has been deployed on MySQL fo...