skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. From the documentation about what goes after the RAISElevel:

    After level if any, you can specify a format string (which must be a simple string literal, not an expression).

    Another name for a string literal is a string constant documented here. Those can use C-like backslash escape sequences: doc

    PostgreSQL also accepts “escape” string constants, which are an extension to the SQL standard. An escape string constant is specified by writing the letter E (upper or lower case) just before the opening single quote, e.g., E'foo'. (When continuing an escape string constant across lines, write E only before the first opening quote.) Within an escape string, a backslash character () begins a C-like backslash escape sequence, in which the combination of backslash and following character(s) represent a special byte value, as shown in Table 4.1.

    Table 4.1. Backslash Escape Sequences

    Backslash Escape Sequence Interpretation
    b backspace
    f form feed
    n newline
    r carriage return
    t tab
    o, oo, ooo (o = 0–7) octal byte value
    xh, xhh (h = 0–9, A–F) hexadecimal byte value
    uxxxx, Uxxxxxxxx (x = 0–9, A–F) 16 or 32-bit hexadecimal Unicode character value

    ‘E’ in RAISE NOTICE E'msg %', mymsg in your opening example is just syntax noise – not particularly magical, not very useful.

    • If 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 use E'...' or not.
    • If 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:

    GET DIAGNOSTICS stack = PG_CONTEXT;
    RAISE NOTICE E'--- Call Stack ---n%', stack;
    

    Note that stack variable also holds newlines of its own and those end up being inserted into the message even if there’s no E out front.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search