728x90
cursor.executemany(sql, data)๋ก ๋ค์์ ๋ก์ฐ ๋ฐ์ดํฐ๋ฅผ INSERT ํ ์ ์๋ค.
sql : INSERT ์ฟผ๋ฆฌ ๋ฌธ์ ๋ฃ์ผ๋ฉด ๋๋ค.
sql = """INSERT INTO TBL_NAME (COL1_NAME, COL2_NAME, COL3_NAME) VALUES(%s,%s,%s)"""
data : sql ์ ๋ ฅ ํ๋ผ๋ฏธํฐ๋ค์ tuple๋ก ๋ง๋ค๊ณ list๋ก ๊ฐ์ธ์ฃผ๋ฉด ๋๋ค.
data = [(parm1,parm2,parm3),(parm1,parm2,parm3),(parm1,parm2,parm3)....]
[ERROR]
TypeError: not all arguments converted during string
sql๋ฌธ์์ ON DUPLICATE KEY UPDATE ์ฌ์ฉ์ ์ฃผ์
[์๋ชป๋ ๋ฐฉ์]
sql = """INSERT INTO TBL_NAME (COL1_NAME,COL2_NAME,COL3_NAME) VALUES(%s, %s,%s)
ON DUPLICATE KEY
UPDATE
COL1_NAME=%s,
COL2_NAME=%s,
COL3_NAME=%s
"""
[์์ ]
sql = """INSERT INTO TBL_NAME (
COL1_NAME,
COL2_NAME,
COL3_NAME
)
VALUES(
%s,
%s,
%s)
ON DUPLICATE KEY
UPDATE
COL1_NAME=VALUES(COL1_NAME),
COL2_NAME=VALUES(COL2_NAME),
COL3_NAME=VALUES(COL3_NAME)
"""
๋ฐ์ํ
'๐ข๏ธ Database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SQL] Count ํจ์, Sequel vs SQL (0) | 2023.08.19 |
---|---|
Apache Parquet(ํ์ผ์ด) (0) | 2023.08.14 |
[์์ธ] Mysql database ์ ๋ ฌ (0) | 2023.07.31 |
[Mysql] Python Sql query Format Error (0) | 2022.03.21 |
[Mysql] Pymysql INSERT ์ฟผ๋ฆฌ ์์ฑ๊ธฐ (0) | 2022.03.21 |