Created
February 16, 2021 00:13
-
-
Save robrich/5b313b4e42a460b50f2a90b41a2bdd23 to your computer and use it in GitHub Desktop.
SQL Programmability with variables in SingleStore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( | |
'select ... into @var' | |
); | |
-- Incorrect syntax: | |
--declare @id bigint; | |
-- Use this instead: | |
select 1 into @id; | |
-- Now use variables: | |
select id, content, createdate | |
from messages | |
where id = @id; | |
-- We can do this in queries as well: | |
select content, createdate into @content, @date | |
from messages | |
where id = 1; | |
select @content, @date; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment