Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DBeaver + Postgres: Debug Function print to output/console

Is it possible to print to either the console window or the output window when debugging Postgres SQL using DBeaver?

If so...HOW? Thanks!

like image 739
learnedOnPascal Avatar asked Jun 17 '26 07:06

learnedOnPascal


2 Answers

You can use in your code:

RAISE NOTICE 'log value %', value ; 

or other debug print and view in "Output" window in DBeaver (second from the bottom icon in the left sql editor panel)

like image 122
szub Avatar answered Jun 19 '26 14:06

szub


You can debug the poor mans way with a Table called PrintOut and a column called messages:

do $$
declare 
ppllastActivity date;
BEGIN
SELECT lastactivity into ppllastActivity FROM People WHERE email = '[email protected]';

IF COALESCE (ppllastActivity, '1900-01-01') = '1900-01-01' THEN
INSERT INTO printout (message) VALUES ('step 1');
END if;

END; $$

SQL to create the sequence, table and timestamp:

-- DROP SEQUENCE public.printout_id_seq;

CREATE SEQUENCE public.printout_id_seq
    INCREMENT BY 1
    MINVALUE 1
     MAXVALUE 9223372036854775807;
    
-- DROP TABLE public.printout;

CREATE TABLE public.printout (
     id INTEGER DEFAULT NEXTVAL('printout_id_seq') NOT NULL,
     message varchar NOT NULL
);

ALTER TABLE printout ADD COLUMN created_at TIMESTAMP;
ALTER TABLE printout ALTER COLUMN created_at SET DEFAULT now();

Then refresh the PrintOut table to see debug messages.

like image 32
Jeremy Thompson Avatar answered Jun 19 '26 15:06

Jeremy Thompson