[PYTHON] SQL notes

what's this

Yaho Where to make a note of cases that are no longer playable when playing sqlite db via python

Parameter specification

There are ? And : payan. It is used when there is only information on a specific column. (I don't want to specify all columns one by one)

query = ('INSERT INTO table (columnA) VALUES (:columnA)')
cursor.execute(query, {'columnA':'hogehoge'})

unconfirmed

Somehow I saw it somewhere like ~~ : = ~~ ** =: ** ... If you use this, can you do it regardless of the contents passed by parameters and the order?

The one who didn't try

query = ('INSERT INTO table (columnA, columnB) VALUES (columnA=:hogeA, columnB=:hogeB)')
cursor.execute(query, {'hogeB':'hogehoge'.'hogeA':'hogege'})

Addendum This is a solution that I noticed just by substituting the parameter of : (Additional note: may not be done)

reference

Crane & to.> Using SQLite3 with Python3 – With sample code from basic operation to error handling Official Python guy stack overflow > sqlite-parameter-substitution-problem

Allocate the latest ID

If a field with the same content exists in a specific column, avoid only ID cover by pushing

INSERT INTO table (id, content) SELECT IFNULL(MAX(id), 0) + 1, content="hogegenoge" FROM table WHERE content

Recommended Posts

SQL notes
JetBrains_Learning Notes_003
SQLAlchemy notes
pyenv notes
Pandas notes
Sphinx notes
django notes
Jupyter_Learning Notes_000
Django notes
pandas self-study notes
Python scraping notes
Mecab installation notes
Python study notes _000
Python learning notes
concurrent.futures Usage notes
Theano installation notes
Jupyter study notes_006
[Django] as_view () notes
Python beginner notes
Theano's basic notes
Python study notes_006
Linux study notes
Notes on Flask
sql from python
Django's order_by notes
Django Template notes
python C ++ notes
Modified SQL Alchemy
pyenv installation notes
Python study notes _005
Python grammar notes
Python Library notes
Examine raw SQL
Hydrogen installation notes
Jupyter study notes_008
python personal notes
Jupyter study notes_004
Notes about pytorch
Jupyter study notes_001
python pandas notes
[Django] JWT notes
Python study notes_001
python learning notes
Python3.4 installation notes
Cabocha installation notes