'Use LPAD with raise info
In postgres when I SELECT LPAD('begin ',50,'*'); it works and shows displays "********************************************begin " which is expected.
I want to use the same in a block with displaying parameter. Using below code.
DO $$
DECLARE
BEGIN
raise info LPAD('begin %',50,' '),clock_timestamp();
raise info LPAD('begin here %',50,' '),clock_timestamp();
raise info LPAD('begin here there %',50,' '),clock_timestamp();
raise info 'begin %',clock_timestamp();
END $$;
I want to display messages with fixed width like columns but it throws error, ERROR: unrecognized exception condition "lpad". Tried many thing but didn't work. Any suggestion to fix this error?
Solution 1:[1]
DO $$
DECLARE a text;
BEGIN
raise info 'begin %', lpad(clock_timestamp()::text, 50, '*');
raise info 'begin %',clock_timestamp();
END $$;
Solution 2:[2]
I have fixed it.
DO $$
DECLARE a text;
BEGIN
raise info '% %', rpad('begin',50,'-'),clock_timestamp();
raise info '% %', rpad('begin here',50,'-'),clock_timestamp();
raise info '% %', rpad('begin here there',50,'-'),clock_timestamp();
END $$;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mark |
| Solution 2 | usersam |
