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

Passing text file input to shell script for Syntaxnet
Can't get attribute 'function_inner' on <module '__mp_main__' from 'E:\\python\\Test\\test.py'>
Python Pandas Get Unique Count of Column
Printing results to text file
comparing and finding error between two arrays of different sizes using numpy
Django filter sort by number of ForeignKey related objects
Pipe the ouput of a hive query run on a remote machine to the local machine using python
Error message installing “Gnuplot-py” with “python setup.py install” command in Mac OS Sierra
Matplotlib plot window is not closing with command-w
uuid with different languages
In Python, how can I get a substring that's in between coordinates XY of another string?
Get index of largest element for each submatrix in a Numpy 2D array
Expand nested data (json, Pandas)
Cassandra DataStax Python driver graceful shutdown logic using Celery
Django Hierarchical Many-to-Many model filtration and representation (self-referencing)
Dupefilter in Scrapy-Redis not working as expected

Categories

HOME
dotnetrdf
sidekiq
erlang
winapi
blockchain
vs-team-services
ruby-on-rails-3
transparent
phonegap-cli
java-home
apiconnect
avl-tree
packer
dryioc
tee
dlib
react-leaflet
line-api
scaling
ada
jogl
boolean-expression
android-fragmentactivity
tweets
apple-tv
url.action
profile
philips-hue
image-quality
chrome-native-messaging
helper
jboss5.x
svnkit
idl
google-drive-realtime-api
reactivemongo
xen
nodeclipse
linq-to-entities
onbackpressed
ical-dotnet
datalog
lftp
rich-text-editor
worker
bids
prototypejs
jtds
livescribe
bnd
decompress
jszip
rxvt
pspice
nsfetchedresultscontrolle
pdflib
cfeclipse
soda
date-format
concur
fill
void
hyperthreading
lmfit
textkit
integral
ibm-data-studio
sqoop2
multipleselection
hana-xs
and-operator
vcl
snmp4j
emma
aquafold
opensocial
winrt-httpclient
onselect
execvp
multiple-conditions
ng-pattern
justgage
prng
objcmongodb
mozart-mvc
usn
couchdb-lucene
pstree
userid
cross-domain-policy
hashalgorithm
text-size
tcxgrid
serp
charts4j
cookieless
ets
pureftpd
boost-date-time
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