http://stackoverflow.com/questions/745538/create-function-through-mysqldb
How can I define a multi-statement function or procedure in using the MySQLdb lib in python? Example: import MySQLdbdb = MySQLdb.connect(db='service') c = db.cursor() c.execute("""DELIMITER // CREATE FUNCTION trivial_func (radius float) RETURNS FLOAT BEGIN IF radius > 1 THEN RETURN 0.0; ELSE RETURN 1.0; END IF; END // DELIMITER ;""") Which creates the following traceback: Traceback (most recent call last): File "proof.py", line 21, in If I copy the same SQL directly into a mysql shell client, it works as expected | |||
|
3 Answers
15accepted | The The purpose of CREATE FUNCTION trivial_func (radius float) RETURNS FLOAT BEGIN IF radius > 1 THEN RETURN 0.0; <-- does this semicolon terminate RETURN or CREATE FUNCTION? ELSE RETURN 1.0; END IF; END Since the API typically allows you to submit one SQL statement at a time, there's no ambiguity -- the interface knows that any semicolons inside the body of your function definition don't terminate the whole |