Skip to content

Instantly share code, notes, and snippets.

@VeryFatBoy
Forked from robrich/sproc-delimiter.sql
Created October 12, 2021 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VeryFatBoy/874e48e693eb987449dc37905ecf2d0e to your computer and use it in GitHub Desktop.
Save VeryFatBoy/874e48e693eb987449dc37905ecf2d0e to your computer and use it in GitHub Desktop.
SingleStore Stored Procedures
CREATE DATABASE IF NOT EXISTS acme;
USE acme;
CREATE TABLE IF NOT EXISTS messages (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
content varchar(300) NOT NULL,
createdate TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO messages (
content
) VALUES (
'building stored procedures'
);
drop procedure if exists messages_update;
-- Switch the delimiter so we can use `;` inside the stored procedure
DELIMITER //
CREATE OR REPLACE PROCEDURE messages_update(_id BIGINT, _content VARCHAR(300)) AS
BEGIN
update messages m set m.content = _content where m.id = _id;
END //
-- And set it back when we're done
DELIMITER ;
call messages_update(1, 'updated via stored procedure');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment