What is the ‘E’ in RAISE NOTICE E'msg %', mymsg
?
I’ve seen it used in various Postgres tutorial pages, even in Postgres documentation itself, but I can’t find an actual explanation of what it is or does.
It’s usually used with messages that use GET STACKED DIAGNOSTICS
, but the message itself only looks to me like a normal
RAISE NOTICE 'foo: %, bar: %',foo_value, bar_value;
type of message where the foo and bar values are simply assigned to the specific diagnostic values in the lines before the RAISE NOTICE.
So, what’s magic about the E'...'
?
2
Answers
I believe in Postgres the "E" signifies the string literal can be escaped, ie, can include escape character sequences, such as a new line escape sequence
n
like in the documentation page you linked to.From the documentation about what goes after the
RAISE
level
:Another name for a string literal is a string constant documented here. Those can use C-like backslash escape sequences: doc
‘E’ in
RAISE NOTICE E'msg %', mymsg
in your opening example is just syntax noise – not particularly magical, not very useful.mymsg
argument contains newlines, or anything requiring some special action to put it there, it will be inserted in place of%
placeholder regardless of whether you useE'...'
or not.mymsg
argument contains backslash escape sequences, those won’t be interpreted as such.In the doc you linked it does make sense since the
n
sequence is in the literal/constant:Note that
stack
variable also holds newlines of its own and those end up being inserted into the message even if there’s noE
out front.