Hi everybody, I hope you’re well! I’m currently working with SingleStore and I would like to know if there is an equivalent of the PRINT T-SQL statement in SingleStore stored procedure. how can i replace If not, will this feature be available in the future?
An other question please, what is the best equivalent of DECLARE TABLE TSQL in Singlestore ?
Have a good day !
SingleStore doesn’t have a PRINT statement like SQL Server, but you can use the ECHO SELECT statement within stored procedures to output messages or results for debugging or informational purposes. For example, you can add ECHO SELECT statements to print messages when certain conditions are met or when handling exceptions in your procedure logic.
E.g. you can write this anon code block and get the results shown:
delimiter //
singlestore> do begin echo select "msg1"; echo select "msg2"; end //
+------+
| msg1 |
+------+
| msg1 |
+------+
1 row in set (0.01 sec)
+------+
| msg2 |
+------+
| msg2 |
+------+
1 row in set (0.01 sec)
You can do it similarly in an SP body.
It works better if you run it from a regular terminal command prompt than in the Helios cloud portal or an IDE because it shows you the output sequentially on the terminal. In the cloud portal, you get each message in a different row output tab.
Regarding a SQL Server DECLARE TABLE equivalent for SingleStore, I think you are talking about SQL Server table variables. We don’t have something exactly analogous to that. Instead, I’d recommend you just use a temp table or a regular table to store intermediate data. If it’s a regular table, you’ll have to delete it before your session ends.