Thread: psql and query buffer mangling

psql and query buffer mangling

From
Daniele Varrazzo
Date:
Hello,

I see psql performs some elaboration on the input query before storing
it in the query buffer: for instance variables are replaced:

    =# \set test 10
    =# select :test;
     ?column?
    ----------
           10
    (1 row)

    =# \p
    select 10;

and comments are stripped:

    duma=# select 1; -- comment
     ?column?
    ----------
            1
    (1 row)

    duma=# \p
    select 1;

Sometimes I use psql to test complex queries which are part of
programs, thus containing placeholders: roundtripping through the
editor via \e will lose the placeholders (as well as the comments)
making harder to test different values and finally to paste back the
query into the program.

Wouldn't be a better behaviour to store the unmodified input into the
query buffer and to perform the required query mangling downstream?

-- Daniele