1

I have a long running update query, for this reason I used the old well known trick of dividing the query in smaller chunks of 1000 to be print the status of the query and calm the anxiety.

Unfortunately DataGrip seems to write to output all the print at the end of the query, witch makes it useless. enter image description here Is it possible to print the updates the same way as Visual Studio? enter image description here

2

2 Answers 2

1

The PRINT statement as you have experienced will not display right away. When you would like to see progress, you can use RAISERROR with NOWAIT for that.v

DECLARE @Msg NVARCHAR(200) = CONCAT('Processing chunk ', @currChunk, ' of ', @numChunks);
RAISERROR(@Msg, 10, 1) WITH NOWAIT;

enter image description here

Shows my result from my testscript:

DECLARE @currChunk INT = 1;
DECLARE @numChunks INT = 20;

WHILE @currChunk < @numChunks
BEGIN

    DECLARE @Msg NVARCHAR(200) = CONCAT('Processing chunk ', @currChunk, ' of ', @numChunks);
    RAISERROR(@Msg, 10, 1) WITH NOWAIT;

    SET @currChunk = @currChunk + 1;

    WAITFOR  DELAY '00:00:02'   /*delay for simulating progress*/

END;

See also: https://www.sqlshack.com/sql-server-print-and-sql-server-raiserror-statements/

2
  • Thanks for the answer the article is also interesting. I tried using raiserror as you suggested but DataGrip in the output window is not showing any progress.
    – s.demuro
    Feb 8 at 9:58
  • @s.demuro, it's up to the application code to display messages as they become available. If DataGroup doesn't show those immediately even with the NOWAIT option, it seems it was not coded to do that like SSMS. Even SSMS will start buffering and delay display when there are many messages.
    – Dan Guzman
    Feb 8 at 10:36
0

In DataGrip 2023.1 suggested code:

DECLARE @currChunk INT = 1;
DECLARE @numChunks INT = 20;

WHILE @currChunk < @numChunks
BEGIN

    DECLARE @Msg NVARCHAR(200) = CONCAT('Processing chunk ', @currChunk, ' of ', @numChunks);
    RAISERROR(@Msg, 10, 1) WITH NOWAIT;

    SET @currChunk = @currChunk + 1;

    WAITFOR  DELAY '00:00:02'   /*delay for simulating progress*/

END;

shows a valid output in console output.

PRINT WORKS CORRECTLY IN DATAGRIP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.