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

How to handle concatenate with empty matrix
python django translation .po and .mo file not translating the files
jupyter not using version set by pyenv
Generalize print+format for a variable number of inputs
What are the differences in these two codes? [closed]
What is the correct way to change image channel ordering between channels first and channels last?
Python to capture screenshot of big file
How can I compare the difference between digits of two numbers?
How to find specific list among other lists
Use variable inside open and also use find and replace in python [on hold]
Can robot framework keyword can be executed in python console?
OpenMDAO/ScipyOptimizer “UnboundLocalError: local variable 'f_new' referenced before assignment”
From C to Python passage by pointer and modification of values [closed]
Is Session.run(fetches) guaranteed to execute its “fetches” arguments in-order?
Return a board read from open file board_file. The board file will contain one row of the board per line
Correlation coefficient and p value for each row within a datafarme

Categories

HOME
json
jdbc
app-inventor
answer-set-programming
nuxeo
avro
csvhelper
couchdb-2.0
jscript
rfc
recyclerview
flyway
browserify
requirejs
netflix-feign
lagom
public-key-encryption
x-frame-options
maxima
react-leaflet
ejs
ada
mousewheel
epicor
spring-ws
header-files
badge
chrome-native-messaging
pcre
canvasjs
service-locator
openpgp
lego
rider
pmwiki
office365connectors
declare
intellilock
crop
powermta
matlab-cvst
facebook-chatbot
lumen-5.3
ajp
goquery
maintenance
text-classification
pagefile
laravel-query-builder
sql-server-administration
rmongodb
mailcatcher
cron-task
django-filer
twgl.js
asymptote
windowlistener
connection-reset
stream-framework
google-hadoop
epl
jazz
virus
uptodate
adodb
tcpreplay
omnifocus
scala-2.11
spdy
android-json-rpc
bignum
layered
robospice
image-zoom
dllexport
gdataxml
linkedhashset
parameterization
point-sprites
nintendo
selectonemenu
webkit-transform
rubycas
rijndael
chatroom
communicationexception
scala-2.8
filetime
database-diagramming

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile