Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create stored procedure with sequelize

I am running the following SQL query:

Executing (default): DROP PROCEDURE IF EXISTS x;

DELIMITER $$
CREATE PROCEDURE x()
BEGIN
    # do something
END $$
DELIMITER; $$

Like so:

sequelize.query(query, {
    type: sequelize.QueryTypes.SELECT
});

But I get this error (even though it works just fine, if I use any other SQL client):

SequelizeDatabaseError: ER_PARSE_ERROR: 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 $$

CREATE PROCEDURE x()

BEGIN

I already added multipleStatements = true to my connection config, but it does not do anything.

Update

I ended up using RAW instead, like so:

sequelize.query(query, {
    type: sequelize.QueryTypes.RAW
});
like image 825
Domi Avatar asked Aug 20 '26 11:08

Domi


2 Answers

DELIMITER is not part of MySQL server, it's part of the MySQL command line client. This feature is not available in the driver.

Source: https://github.com/mysqljs/mysql/issues/280#issuecomment-8081626

like image 166
Eduardo Cuomo Avatar answered Aug 22 '26 01:08

Eduardo Cuomo


Your error is actually in the last line. Take out the $$ after DELIMITER; The statement: DELIMITER; resets the delimiter to ; the $$ after that confuses the syntax analyzer.

like image 21
Richard Knouse Avatar answered Aug 22 '26 01:08

Richard Knouse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!