python


MYsql Stored procedure only work the second time i execute it through python


I'm using python to create a data warehouse in MySQL.
I'm using the MySQLdb package to connect python to MySQL.
I am trying to create a table which will contain all dates from 2005 to 2018.
First, I create the relevant table:
cursor.execute("""
CREATE TABLE IF NOT EXISTS dim_date (
date_id int(11) NOT NULL AUTO_INCREMENT,
date date,
day int(11),
month int(11),
year int(11),
day_name varchar(45),
PRIMARY KEY (date_id),
INDEX date_index (date))
""")
Then, I run the following command to create and run the stored procedure that will fill in the dates:
cursor.execute("DROP PROCEDURE IF EXISTS BuildDate;")
cursor.execute("SET #currdate := '2005-01-01';")
cursor.execute("SET #enddate := '2018-01-01';")
cursor.execute("""
CREATE PROCEDURE BuildDate()
BEGIN
WHILE #currdate < #enddate DO
INSERT INTO ntr_yelp_dw.dim_date (date, day, month, year, day_name)
VALUES (
#currdate, DAY(#currdate), MONTH(#currdate),
YEAR(#currdate), DAYNAME(#currdate)
);
SET #currdate := DATE_ADD(#currdate, INTERVAL 1 DAY);
END WHILE;
END
""")
cursor.callproc("BuildDate")
The thing is that when I run the stored procedure code, the stored procedure is created, but the data isn't filled.
Only when I run it a second time, the data is created and inserted into the table.
Any thoughts?

Related Links

“myobject” is not Iterable, but my obect is erased
SSL Certification Error > hostname doesn't match
Sequencing of elements in dict python
Keras error : Expected to see 1 array
import mxnet dmlc error Entry add_n already registered under different entry
How to open and execute kill task code through html
how do I remove unwanted empty dimension from xarray DataArray (squeeze doesn't work)
How to do math expression from input() in Python?
opening luigi.LocalTarget in binary read mode (decoding error)
GPU slows way down after a few loops
Google's verify_id_token function not working
ImportError: libgomp.so.1: cannot open shared object file: No such file or directory
Django Iterating through an object set with unique_together and no pk
Can i deploy a Django project using Apache that is not located in /var/www?
How to run a python script on images present in firebase?
dictionary variable formatting in Python's Mysqldb

Categories

HOME
tensorflow
jenkins-plugins
shopify
wmic
voip
google-tag-manager
ocaml
formal-verification
zend-framework2
branch.io
adsense
ext.net
subquery
eval
desktop
hosts
cortex-a
store
rapidjson
uisplitviewcontroller
ssms-2016
bootstrap-popover
pycrypto
backpropagation
fop
azure-servicebus-queues
fabric
activepython
geopandas
jenkins-job-dsl
thinking-sphinx
red-black-tree
hibernate-cache
graph-databases
ifstream
web-audio-api
modulo
node-horseman
es-shell
onbackpressed
google-account
cppunit
prototypejs
estimation
nsjsonserialization
sgmlreader
istorage
google-maps-ios
info
photography
execl
pycurl
emoticons
communication-protocol
date-range
gmt
gradle-script-kotlin
alter
rmongodb
uistackview
pax-web
multifile-uploader
freefem++
asp.net-mvc-partialview
supportmapfragment
qt-linguist
fortran90
spservices
multinomial
cctray
throughput
coldfusion-7
geodjango
insert-into
response-headers
twython
adobe-indesign
jython-2.7
formvalidation-plugin
docopt
mov
genetic-programming
dto
proxies
bsp
alertifyjs
sgml
ksoap2
chrome-for-android
circos
sim900
osx-snow-leopard
goinstant
image-zoom
swrl
stagefright
transitive-closure-table
tridion2009
lync-server-2010
moq-3
unions
isolatedstorage
msgbox
wchar
nemerle
newsstand-kit
ets
ruby-debug
nagle
pivotal-crm
getresource
sitemappath
multibyte-functions
openwysiwyg
windows-controls
data-entry
outlook-form

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App