Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 181637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:47:56+00:00 2026-05-11T14:47:56+00:00

How can I define a multi-statement function or procedure in using the MySQLdb lib

  • 0

How can I define a multi-statement function or procedure in using the MySQLdb lib in python?

Example:

import MySQLdb  db = 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 <module>     DELIMITER ;''')   File 'build/bdist.macosx-10.5-i386/egg/MySQLdb/cursors.py', line 173, in execute   File 'build/bdist.macosx-10.5-i386/egg/MySQLdb/connections.py', line 35, in defaulterrorhandler _mysql_exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER //\nCREATE FUNCTION trivial_func (radius float) \n    RETURNS FLOAT\n\n   ' at line 1') 

If I copy the same SQL directly into a mysql shell client, it works as expected

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:47:56+00:00Added an answer on May 11, 2026 at 2:47 pm

    The DELIMITER command is a MySQL shell client builtin, and it’s recognized only by that program (and MySQL Query Browser). It’s not necessary to use DELIMITER if you execute SQL statements directly through an API.

    The purpose of DELIMITER is to help you avoid ambiguity about the termination of the CREATE FUNCTION statement, when the statement itself can contain semicolon characters. This is important in the shell client, where by default a semicolon terminates an SQL statement. You need to set the statement terminator to some other character in order to submit the body of a function (or trigger or procedure).

    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 CREATE FUNCTION statement. So there’s no need to change the statement terminator with DELIMITER.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 101k
  • Answers 101k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't retain value in FileUpload control. This is because… May 11, 2026 at 8:02 pm
  • Editorial Team
    Editorial Team added an answer From the Standard, 15.1/8 If no exception is presently being… May 11, 2026 at 8:02 pm
  • Editorial Team
    Editorial Team added an answer FOr your answer to number 1: In terms of security,… May 11, 2026 at 8:02 pm

Related Questions

We are building a multi-tenant website in ASP.NET, and we must let each customer
What follows is a regular expression I have written to match multi-line pre-processor macros
In C++, say you want to declare a global variable to be used by
We're writing a records management product for schools and one of the requirements is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.