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

Updating a value in a Pandas dataframe seems to update all dataframes
4 entry box nummeric keypad
os.walk for loop not executing [duplicate]
python matplotlib polar plot
Django - not showing properly one of my tables in template
Datalab: How to export Big Query standard SQL query to dataframe?
Pandas: count difference between dates
Skip one line in .csv file by using genfromtxt function in python
Dealing with NaNs in Pandas
Python Script? - Logging serial output from arduino
Iterate links from selenium into bs4 and print stripped strings
Query for only part of objects of related_name (from ForeignKey)
How to fill in missing sequence lines in a TSV file
Django website optimization: Too many calls to core python functions?
How to post issues to gitlab using python?
Coverage and nose shows files from django and not just my tests

Categories

HOME
laravel-5
cil
sass
elixir
vhdl
mapping
warnings
visual-studio-2013
amazon-product-api
ruby-on-rails-3
matplotlib
user
devstack
shipping
jboss-eap-7
cortex-a
uiview
glpk
ssms-2016
grub2
flat-file
multiple-columns
jconsole
avplayeritem
ab-initio
gpib
lmdb
entity-system
hawtio
modelandview
qtablewidget
modulo
color-scheme
pmwiki
rhel.net
strstr
concrete5-5.7
lexical-analysis
tripwire
jrules
google-account
android-maps-v2
estimation
ajp
defold
sgmlreader
slot
settimeout
bacnet
boost-hana
inotifypropertychanged
uwp-maps
multilingual-app-toolkit
concur
document-oriented-db
lmfit
futuretask
mptcp
isml
left-recursion
omnifocus
node-imagemagick
ifft
map-force
crystal-reports-10
uipickerviewcontroller
pep8
qtgui
zend-lucene
database-permissions
vertical-scrolling
mvs
qsqltablemodel
autostart
deploying
redirectstandardoutput
ninject-extensions
getstring
hibernate3
fileutils
easygui
opengl-es-lighting
rubycas
dcpu-16
pantheios
j-interop
visual-c++-2008-express
web-statistics
revision
odbc-sql-server-driver
msf
standardized

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