peewee mysql how to execute 'insert many on duplicate key update'
See original GitHub issueHi Charles, how to execute sql command like
insert into table(ip,hostname,...)
values
('','',...)
('','',...)
('','',...)
...
on duplicate key update hostname=values(hostname),
upsert and on_conflict does not work
In [49]: result
Out[49]:
[{'country': '',
'guid': '122.225.227.21:80',
'head': '',
'hostname': '122.225.227.21',
'ip': '122.225.227.21',
'ipr': '',
'port': 80,
'protocol_type': 'tcp',
'province': '',
'server': '',
'title': ''},
...]
In [50]: basicinfo_ip_finger.insert_many(result).on_conflict('REPLACE').execute()
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR REPLACE INTO `basicinfo_ip_finger` (`ip`, `port`, `protocol_type`, `hostname`' at line 1")
please help, thanks
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How can I insert multiple rows with INSERT REPLACE in ...
The problem is that some of the rows may already exist in my database. The solution should be to either ignore or replace...
Read more >Querying — peewee 3.15.4 documentation
After executing the insert query, the primary key of the new row is returned. ... MySQL supports upsert via the ON DUPLICATE KEY...
Read more >Build a MySQL upsert query to insert/update multiple records ...
Use transactions by initialising your cursors using with database.cursor() as cursor: You'll want to run your code through pep8 to improve ...
Read more >peewee — pyknotid 0.5.4 documentation - Read the Docs
_columns else self.c for key, value in kwargs.items(): insert[getattr(src, ... SQL('='), v))) if updates: return NodeList((SQL('ON DUPLICATE KEY UPDATE'), ...
Read more >peewee Documentation [image] - manpages.ubuntu!
When you call save(), peewee determines whether to do an INSERT versus an UPDATE based on ... MySQL supports upsert via the ON...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Peewee does support ON DUPLICATE KEY UPDATE:
http://docs.peewee-orm.com/en/latest/peewee/querying.html#upsert
here is my poor solution
any good idea? thanks