Thread

Commits

  1. psql: initialize comment-begin setting to a useful value by default.

  2. psql: treat "--" comments between queries as separate history entries.

  3. psql: include intra-query "--" comments in what's sent to the server.

  1. Correct handling of blank/commented lines in PSQL interactive-mode history

    Greg Nancarrow <gregn4422@gmail.com> — 2021-09-06T14:13:35Z

    Hi,
    
    Single lines entered in PSQL interactive-mode, containing just
    whitespace or an SQL comment ("--..."), don't seem to be stored
    correctly in the history.
    For example, such lines are currently prepended to the history of the
    next command entered, rather than having their own history entry.
    Also, if HISTCONTROL=ignorespace is in effect, if a line is entered
    that starts with a space and the rest of the line is whitespace or an
    SQL comment, then it prevents the next command entered from being
    saved in the history.
    
    I've attached a patch that corrects the behaviour.
    For the type of lines mentioned, the patch makes the history behave
    more like Bash history.
    
    [I noticed this problem in PSQL interactive-mode history when typing
    in a long SQL command which I then decided to just comment, using a
    "--" prefix, and enter it, to store it in the history, so I could
    later recall it from the history after first executing some other
    commands.]
    
    
    Below are some examples of problem scenarios, and results BEFORE/AFTER
    the patch is applied:
    
    (1)
    
    <space><ENTER>
    SELECT 1;<ENTER>
    
    BEFORE PATCH:
    Results in a single history entry, with <space> on the 1st line and
    "SELECT 1;" on the 2nd line.
    AFTER PATCH:
    Results in two history entries, 1st contains <space> and the 2nd
    contains "SELECT 1;".
    
    
    (2)
    
    -- my comment<ENTER>
    SELECT 1;<ENTER>
    
    BEFORE PATCH:
    Results in a single history entry, containing "-- my comment" on the
    1st line and "SELECT 1;" on the 2nd line.
    AFTER PATCH:
    Results in two history entries, 1st contains "-- my comment" and the
    2nd contains "SELECT 1;".
    
    
    (3)
    {--variable=HISTCONTROL=ignorespace}
    
    <space><ENTER>
    SELECT 1;<ENTER>
    
    BEFORE PATCH:
    No history entry is saved.
    AFTER PATCH:
    Results in one history entry, containing "SELECT 1;".
    
    
    (4)
    {--variable=HISTCONTROL=ignorespace}
    
    <space>-- my comment<ENTER>
    SELECT 1;<ENTER>
    
    BEFORE PATCH:
    No history entry is saved.
    AFTER PATCH:
    Results in one history entry, containing "SELECT 1;".
    
    
    Regards,
    Greg Nancarrow
    Fujitsu Australia
    
  2. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    David G. Johnston <david.g.johnston@gmail.com> — 2021-09-06T14:50:15Z

    On Mon, Sep 6, 2021 at 7:13 AM Greg Nancarrow <gregn4422@gmail.com> wrote:
    
    > I've attached a patch that corrects the behaviour.
    > For the type of lines mentioned, the patch makes the history behave
    > more like Bash history.
    >
    
    I have my doubts that you've really fixed anything here since Bash is a
    line-oriented shell while psql is a statement-oriented one.  This is a
    feature.
    
    What you are observing is, I think, a side-effect of that fact that
    comments cannot terminate statements.  That seems reasonable.  In short,
    your BEFORE results make sense and don't require fixing.
    
    David J.
    
  3. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Laurenz Albe <laurenz.albe@cybertec.at> — 2021-09-06T16:02:45Z

    On Mon, 2021-09-06 at 07:50 -0700, David G. Johnston wrote:
    > On Mon, Sep 6, 2021 at 7:13 AM Greg Nancarrow <gregn4422@gmail.com> wrote:
    > > I've attached a patch that corrects the behaviour.
    > > For the type of lines mentioned, the patch makes the history behave
    > > more like Bash history.
    > 
    > I have my doubts that you've really fixed anything here since Bash is a
    > line-oriented shell while psql is a statement-oriented one.  This is a feature.
    > What you are observing is, I think, a side-effect of that fact that
    > comments cannot terminate statements.  That seems reasonable.
    > In short, your BEFORE results make sense and don't require fixing.
    
    I think that psql's behavior should be governed more by usefulness than
    by consideratoins like "comments cannot terminate statements".
    
    I agree with Greg that the current behavior is annoying and would
    welcome the change.  This has bothered me before.
    
    That multi-line statements that contain a line with a space are omitted
    from the history when HISTCONTROL is set to "ignorespace" seems like
    a bug to me.
    
    So +1 on the idea of the patch, although I didn't scrutinize the
    implementation.
    
    Yours,
    Laurenz Albe
    
    
    
    
    
  4. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Justin Pryzby <pryzby@telsasoft.com> — 2021-09-06T19:37:31Z

    On Mon, Sep 06, 2021 at 07:50:15AM -0700, David G. Johnston wrote:
    > On Mon, Sep 6, 2021 at 7:13 AM Greg Nancarrow <gregn4422@gmail.com> wrote:
    > > I've attached a patch that corrects the behaviour.
    > > For the type of lines mentioned, the patch makes the history behave
    > > more like Bash history.
    
    The behavior of bash is configurable here:
    
    |HISTCONTROL
    |      A  colon-separated  list  of  values controlling how commands are saved on the history list.  If the list of values includes ignorespace, lines which begin with a space character are not saved in the history
    |      list....
    
    > I have my doubts that you've really fixed anything here since Bash is a
    > line-oriented shell while psql is a statement-oriented one.  This is a
    > feature.
    
    Hm, I don't think bash is "line oriented" ?  You can type anything into it that
    you'd put in a shell script.  For example:
    
    $ for a in `seq 1 3`
    > do
    > echo $a
    > done
    1
    2
    3
    
    -- 
    Justin
    
    
    
    
  5. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Alvaro Herrera <alvherre@alvh.no-ip.org> — 2021-09-07T00:28:53Z

    On 2021-Sep-06, Laurenz Albe wrote:
    
    > I agree with Greg that the current behavior is annoying and would
    > welcome the change.  This has bothered me before.
    
    It has bothered me too.  I am particularly bothered by the uselessness
    that M-# results in -- namely, inserting a # at the start of the buffer.
    This is quite useless: in bash, the # starts a comment, so M-# makes the
    entry a comment; but in psql it doesn't have that effect.  If somebody
    were to make M-# make the buffer a /* ... */ comment, it would become
    quite handy.
    
    -- 
    Álvaro Herrera           39°49'30"S 73°17'W  —  https://www.EnterpriseDB.com/
    
    
    
    
  6. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-09-07T18:50:51Z

    Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
    > On 2021-Sep-06, Laurenz Albe wrote:
    >> I agree with Greg that the current behavior is annoying and would
    >> welcome the change.  This has bothered me before.
    
    > It has bothered me too.
    
    I'm not here to claim that the current behavior is perfect.  However,
    AFAICT the patch as-presented breaks the principle that text goes into
    the history at the moment it's sent to the server.  In particular, we
    might make an entry for text that *never* got to the server because you
    cleared the buffer instead.  I don't find that to be an improvement.
    It breaks one of the primary use-cases for history, ie keeping a record
    of what you did.
    
    We could perhaps finesse that point by deciding that comment lines
    that are handled this way will never be sent to the server --- but
    I'm sure people will complain about that, too.  I've definitely heard
    people complain because "--" comments are stripped from what's sent
    (so I'd look favorably on a patch to undo that).
    
    I think the questions around empty-line handling are largely
    orthogonal to this, and we'll just confuse ourselves if we
    discuss that at the same time.  Likewise for M-#.
    
    			regards, tom lane
    
    
    
    
  7. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-09-07T19:16:25Z

    [ this is a digression from the main point of the thread, but ... ]
    
    Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
    > I am particularly bothered by the uselessness
    > that M-# results in -- namely, inserting a # at the start of the buffer.
    
    Fixing that might be as simple as the attached.  I've not beat on
    it hard though.
    
    			regards, tom lane
    
    
  8. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Peter Eisentraut <peter.eisentraut@enterprisedb.com> — 2021-09-17T09:11:35Z

    On 07.09.21 21:16, Tom Lane wrote:
    > [ this is a digression from the main point of the thread, but ... ]
    > 
    > Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
    >> I am particularly bothered by the uselessness
    >> that M-# results in -- namely, inserting a # at the start of the buffer.
    > 
    > Fixing that might be as simple as the attached.  I've not beat on
    > it hard though.
    
    I see this in my .inputrc, although I don't remember when/how I put it 
    there:
    
    $if psql
    set comment-begin --
    set expand-tilde on
    $endif
    
    
    
    
  9. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-11-27T23:30:30Z

    I wrote:
    > We could perhaps finesse that point by deciding that comment lines
    > that are handled this way will never be sent to the server --- but
    > I'm sure people will complain about that, too.  I've definitely heard
    > people complain because "--" comments are stripped from what's sent
    > (so I'd look favorably on a patch to undo that).
    
    In hopes of moving this thread forward, I experimented with doing that
    bit, basically by simplifying the {whitespace} rule in psqlscan.l
    to be just "ECHO;".  That caused massive regression test failures,
    of which this'll do as a sample:
    
     --
     -- This should fail
     --
     copy (select * from test1) (t,id) to stdout;
     ERROR:  syntax error at or near "("
    -LINE 1: copy (select * from test1) (t,id) to stdout;
    +LINE 4: copy (select * from test1) (t,id) to stdout;
                                        ^
     --
     -- Test JOIN
    
    Of course, the problem is that since we're now including the three "--"
    lines in what's sent to the server, it thinks the "copy" is on line 4.
    I do not think we want such a behavior change: people don't tend to
    think that such comments are part of the query.
    
    I then experimented with combining the psqlscan.l change with mainloop.c
    changes akin to what Greg had proposed, so as to discard leading comments
    at the level of mainloop.c rather than inside the lexer.  I didn't have
    much luck getting to a behavior that I thought could be acceptable,
    although maybe with more sweat it'd be possible.
    
    One thing I noticed along the line is that because the history mechanism
    records raw input lines while psqlscan.l discards dash-dash comments,
    it's already the case that history entries don't match up too well with
    what's sent to the server.  So I'm not sure that my upthread complaint
    about that holds water, and I'm less against Greg's original patch than
    I was.
    
    Trying to gather together the various issues mentioned on this thread,
    I see:
    
    * Initial input lines that are blank (whitespace, maybe including a
    comment) are merged into the next command's history entry; but since
    said lines don't give rise to any text sent to the server, there's
    not really any reason why they couldn't be treated as text to be
    emitted to the history file immediately.  This is what Greg originally
    set out to change.  After my experiments mentioned above, I'm quite
    doubtful that his patch is correct in detail (I'm afraid that it
    probably emits stuff too soon in some cases), but it could likely be
    fixed if we could just get agreement that a change of that sort is OK.
    
    * It's not great that dash-dash comments aren't included in what we
    send to the server.  However, changing that is a lot trickier than
    it looks.  I think we want to continue suppressing comments that
    precede the query proper.  Including comments that are within the
    query text (ahead of the trailing semi) is not so hard, but comments
    following the semicolon look too much like comments-ahead-of-the-
    next-query.  Perhaps that issue should be left for another day ...
    although it does feel like it interacts with the first point.
    
    * Misbehavior of M-# was also mentioned.  Does anyone object to
    the draft patch I posted for that?
    
    			regards, tom lane
    
    
    
    
  10. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Laurenz Albe <laurenz.albe@cybertec.at> — 2021-11-29T08:07:48Z

    On Sat, 2021-11-27 at 18:30 -0500, Tom Lane wrote:
    > Trying to gather together the various issues mentioned on this thread,
    > I see:
    > 
    > * Initial input lines that are blank (whitespace, maybe including a
    > comment) are merged into the next command's history entry; but since
    > said lines don't give rise to any text sent to the server, there's
    > not really any reason why they couldn't be treated as text to be
    > emitted to the history file immediately.  This is what Greg originally
    > set out to change.  After my experiments mentioned above, I'm quite
    > doubtful that his patch is correct in detail (I'm afraid that it
    > probably emits stuff too soon in some cases), but it could likely be
    > fixed if we could just get agreement that a change of that sort is OK.
    
    For me, it is just a mild annoyance to have unrelated comments
    preceding the query be part of the query's history file entry.
    If that is difficult to improve, I can live with it the way it is.
    
    > * It's not great that dash-dash comments aren't included in what we
    > send to the server.  However, changing that is a lot trickier than
    > it looks.  I think we want to continue suppressing comments that
    > precede the query proper.  Including comments that are within the
    > query text (ahead of the trailing semi) is not so hard, but comments
    > following the semicolon look too much like comments-ahead-of-the-
    > next-query.  Perhaps that issue should be left for another day ...
    > although it does feel like it interacts with the first point.
    
    If we treat double-dash comments differently from /* */ ones,
    that is indeed odd.  I personally haven't been bothered by it, though.
    
    > * Misbehavior of M-# was also mentioned.  Does anyone object to
    > the draft patch I posted for that?
    
    No, I think that is a clear improvement.
    
    There was one other problem mentioned in the original mail, and that
    seems to be the most serious one to me:
    
    > psql
    psql (14.1)
    Type "help" for help.
    
    test=> \set HISTCONTROL ignorespace                       
    test=>   -- line that starts with space
    test=> SELECT 42;
     ?column? 
    ══════════
           42
    (1 row)
    
    Now that query is not added to the history file at all.
    
    Yours,
    Laurenz Albe
    
    
    
    
    
  11. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-11-29T14:43:56Z

    Laurenz Albe <laurenz.albe@cybertec.at> writes:
    > There was one other problem mentioned in the original mail, and that
    > seems to be the most serious one to me:
    > [ HISTCONTROL behavior ]
    
    The actual behavior of that option (which perhaps isn't adequately
    documented) is that it suppresses a history entry if the first
    character of the possibly-multi-line entry is a space.  It certainly
    can't operate on a per-line basis, or you'd be likely to lose chunks
    of a single SQL command, so I think that definition is fine as
    it is (ignoring the whole question of whether the feature is sane
    at all ... but if you don't think so, why would you use it?)
    
    Greg's patch would fix this specifically by ensuring that the line
    with the space and comment is treated as a separate history entry.
    So I don't really see that as a separate bug.  Or, if you will,
    the fact that people see it as a bug confirms that such a line
    should be treated as a separate history entry.
    
    			regards, tom lane
    
    
    
    
  12. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Alvaro Herrera <alvherre@alvh.no-ip.org> — 2021-11-29T15:23:46Z

    On 2021-Nov-29, Tom Lane wrote:
    
    > Greg's patch would fix this specifically by ensuring that the line
    > with the space and comment is treated as a separate history entry.
    > So I don't really see that as a separate bug.  Or, if you will,
    > the fact that people see it as a bug confirms that such a line
    > should be treated as a separate history entry.
    
    I wonder if these things would be easier to deal with or more convenient
    if we thought of -- as starting a line-scoped comment, and /* */ as
    starting a query-scoped comment, and treat both types differently.  That
    is, a -- comment would not be part of the subsequent command (and they
    would become two separate history entries), but a /* */ comment would be
    part of the command, and so both the comment and the query would be
    saved as a single history entry.
    
    So with ignorespace, then you can get either behavior:
    
     /* don't put neither comment nor command in history */
    select 1;
    and then nothing gets put in history; but if you do
    
     -- don't put this *comment* in history, but do put command
    select 1;
    
    then the comment is ignored, but the query does end up in history.
    
    
    Perhaps one problem is how to behave with intra-query -- comments.
    Surely they should not split the command in three parts, but I'm not
    sure to what extent that is possible to implement.
    
    This doesn't actually fix the issue that Greg was complaining about,
    because his problem is precisely the -- comments.  But would Greg and
    other users be satisfied if we made that distinction?
    
    -- 
    Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
    
    
    
    
  13. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Laurenz Albe <laurenz.albe@cybertec.at> — 2021-11-29T15:25:04Z

    On Mon, 2021-11-29 at 09:43 -0500, Tom Lane wrote:
    > Laurenz Albe <laurenz.albe@cybertec.at> writes:
    > > There was one other problem mentioned in the original mail, and that
    > > seems to be the most serious one to me:
    > > [ HISTCONTROL behavior ]
    > 
    > The actual behavior of that option (which perhaps isn't adequately
    > documented) is that it suppresses a history entry if the first
    > character of the possibly-multi-line entry is a space.  It certainly
    > can't operate on a per-line basis, or you'd be likely to lose chunks
    > of a single SQL command, so I think that definition is fine as
    > it is (ignoring the whole question of whether the feature is sane
    > at all ... but if you don't think so, why would you use it?)
    > 
    > Greg's patch would fix this specifically by ensuring that the line
    > with the space and comment is treated as a separate history entry.
    > So I don't really see that as a separate bug.  Or, if you will,
    > the fact that people see it as a bug confirms that such a line
    > should be treated as a separate history entry.
    
    Ah, yes.  You are right with both the explanation for the behavior
    and stating that it points towards treating leading comments as
    being seperate from the query.
    
    And, thinking about HISTCONTROL, it does not seem sane in the
    context of SQL, and I would never use it.
    
    Yours,
    Laurenz Albe
    
    
    
    
    
  14. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-11-29T15:58:44Z

    Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
    > I wonder if these things would be easier to deal with or more convenient
    > if we thought of -- as starting a line-scoped comment, and /* */ as
    > starting a query-scoped comment, and treat both types differently.  That
    > is, a -- comment would not be part of the subsequent command (and they
    > would become two separate history entries), but a /* */ comment would be
    > part of the command, and so both the comment and the query would be
    > saved as a single history entry.
    
    The hack I was fooling with yesterday would have had that effect,
    although it was a consequence of the fact that I was too lazy
    to parse slash-star comments ;-).  But basically what I was
    trying to do was to force a line that was only whitespace
    (possibly plus dash-dash comment) to be treated as a separate
    history entry, while not suppressing dash-dash comments
    altogether as the current code does.
    
    			regards, tom lane
    
    
    
    
  15. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-11-29T20:56:28Z

    After some further hackery, here's a set of patches that I think
    might be acceptable.  They're actually fairly independent, although
    they touch different aspects of the same behavior.
    
    0001 gets rid of psqlscan.l's habit of suppressing dash-dash comments,
    but only once we have collected some non-whitespace query input.
    The upshot of this is that dash-dash comments will get sent to the
    server as long as they are within the query proper, that is after the
    first non-whitespace token and before the ending semicolon.  Comments
    that are between queries are still suppressed, because not doing that
    seems to result in far too much behavioral change.  As it stands,
    though, there are just a few regression test result changes.
    
    0002 is a simplified version of Greg's patch.  I think we only need
    to look at the state of the query_buf to see if any input has been
    collected in order to determine if we are within or between queries.
    I'd originally thought this'd need to be a lot more complicated,
    but as long as psqlscan.l continues to drop pre-query comments,
    this seems to be enough.
    
    0003 is the same patch I posted before to adjust M-# behavior.
    
    			regards, tom lane
    
    
  16. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Greg Nancarrow <gregn4422@gmail.com> — 2021-11-29T23:37:42Z

    On Tue, Nov 30, 2021 at 7:56 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    >
    > After some further hackery, here's a set of patches that I think
    > might be acceptable.  They're actually fairly independent, although
    > they touch different aspects of the same behavior.
    >
    > 0001 gets rid of psqlscan.l's habit of suppressing dash-dash comments,
    > but only once we have collected some non-whitespace query input.
    > The upshot of this is that dash-dash comments will get sent to the
    > server as long as they are within the query proper, that is after the
    > first non-whitespace token and before the ending semicolon.  Comments
    > that are between queries are still suppressed, because not doing that
    > seems to result in far too much behavioral change.  As it stands,
    > though, there are just a few regression test result changes.
    >
    > 0002 is a simplified version of Greg's patch.  I think we only need
    > to look at the state of the query_buf to see if any input has been
    > collected in order to determine if we are within or between queries.
    > I'd originally thought this'd need to be a lot more complicated,
    > but as long as psqlscan.l continues to drop pre-query comments,
    > this seems to be enough.
    >
    > 0003 is the same patch I posted before to adjust M-# behavior.
    >
    
    I did some testing of the patches against the 4 problems that I
    originally reported, and they fixed all of them.
    0002 is definitely simpler than my original effort.
    The patches LGTM.
    Thanks for working on this.
    (BTW, the patches are in Windows CRLF format, so on Linux at least I
    needed to convert them using dos2unix so they'd apply using Git)
    
    Regards,
    Greg Nancarrow
    Fujitsu Australia
    
    
    
    
  17. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Alvaro Herrera <alvherre@alvh.no-ip.org> — 2021-11-29T23:58:58Z

    On 2021-Nov-29, Tom Lane wrote:
    
    > After some further hackery, here's a set of patches that I think
    > might be acceptable.  They're actually fairly independent, although
    > they touch different aspects of the same behavior.
    
    I tried the collection and I find the overall behavior quite convenient.
    I think it works just as I wish it would.
    
    -- 
    Álvaro Herrera           39°49'30"S 73°17'W  —  https://www.EnterpriseDB.com/
    "The eagle never lost so much time, as
    when he submitted to learn of the crow." (William Blake)
    
    
    
    
  18. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-11-30T00:08:26Z

    Greg Nancarrow <gregn4422@gmail.com> writes:
    > (BTW, the patches are in Windows CRLF format, so on Linux at least I
    > needed to convert them using dos2unix so they'd apply using Git)
    
    Hmm.  Applying "od -c" to the copy of that message that's in my
    PG list folder shows clearly that there's no \r in it, nor do
    I see any when I save off the attachment.  I suppose this must
    be an artifact of the way that your MUA treats text attachments;
    or maybe the mail got mangled on its way to you.
    
    			regards, tom lane
    
    
    
    
  19. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Greg Nancarrow <gregn4422@gmail.com> — 2021-11-30T01:15:32Z

    On Tue, Nov 30, 2021 at 11:08 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    >
    > Greg Nancarrow <gregn4422@gmail.com> writes:
    > > (BTW, the patches are in Windows CRLF format, so on Linux at least I
    > > needed to convert them using dos2unix so they'd apply using Git)
    >
    > Hmm.  Applying "od -c" to the copy of that message that's in my
    > PG list folder shows clearly that there's no \r in it, nor do
    > I see any when I save off the attachment.  I suppose this must
    > be an artifact of the way that your MUA treats text attachments;
    > or maybe the mail got mangled on its way to you.
    >
    
    Yeah, sorry, looks like it could be a Gmail issue for me.
    When I alternatively downloaded your patches from the pgsql-hackers
    archive, they're in Unix format, as you say.
    After a bit of investigation, it seems that patch attachments (like
    yours) with a Context-Type of "text/x-diff" download through Gmail in
    CRLF format for me (I'm running a browser on Windows, but my Postgres
    development environment is in a Linux VM). So those must get converted
    from Unix to CRLF format if downloaded using a browser running on
    Windows.
    The majority of patch attachments (?) seem to have a Context-Type of
    "application/octet-stream" or "text/x-patch", and these seem to
    download raw (in their original Unix format).
    I guess the attachment context-type is varying according to the mail
    client used for posting.
    
    Sorry for the noise.
    
    Regards,
    Greg Nancarrow
    Fujitsu Australia
    
    
    
    
  20. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Greg Nancarrow <gregn4422@gmail.com> — 2021-11-30T02:21:47Z

    On Tue, Nov 30, 2021 at 12:15 PM Greg Nancarrow <gregn4422@gmail.com> wrote:
    >
    > Yeah, sorry, looks like it could be a Gmail issue for me.
    > When I alternatively downloaded your patches from the pgsql-hackers
    > archive, they're in Unix format, as you say.
    > After a bit of investigation, it seems that patch attachments (like
    > yours) with a Context-Type of "text/x-diff" download through Gmail in
    > CRLF format for me (I'm running a browser on Windows, but my Postgres
    > development environment is in a Linux VM). So those must get converted
    > from Unix to CRLF format if downloaded using a browser running on
    > Windows.
    > The majority of patch attachments (?) seem to have a Context-Type of
    > "application/octet-stream" or "text/x-patch", and these seem to
    > download raw (in their original Unix format).
    > I guess the attachment context-type is varying according to the mail
    > client used for posting.
    >
    
    Oops, typos, I meant to say "Content-Type".
    
    Regards,
    Greg Nancarrow
    Fujitsu Australia
    
    
    
    
  21. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-11-30T04:12:35Z

    Greg Nancarrow <gregn4422@gmail.com> writes:
    > After a bit of investigation, it seems that patch attachments (like
    > yours) with a Context-Type of "text/x-diff" download through Gmail in
    > CRLF format for me (I'm running a browser on Windows, but my Postgres
    > development environment is in a Linux VM). So those must get converted
    > from Unix to CRLF format if downloaded using a browser running on
    > Windows.
    > The majority of patch attachments (?) seem to have a Context-Type of
    > "application/octet-stream" or "text/x-patch", and these seem to
    > download raw (in their original Unix format).
    
    Interesting.  I can probably adjust my MUA to send "text/x-patch",
    but I'll have to look around to see where that's determined.
    (I dislike using "application/octet-stream" for this, because
    the archives won't show that as text, they only let you download
    the attachment.  Maybe that's more Safari's fault than the
    archives per se, not sure.)
    
    			regards, tom lane
    
    
    
    
  22. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Bruce Momjian <bruce@momjian.us> — 2021-11-30T21:26:53Z

    On Mon, Nov 29, 2021 at 11:12:35PM -0500, Tom Lane wrote:
    > Greg Nancarrow <gregn4422@gmail.com> writes:
    > > After a bit of investigation, it seems that patch attachments (like
    > > yours) with a Context-Type of "text/x-diff" download through Gmail in
    > > CRLF format for me (I'm running a browser on Windows, but my Postgres
    > > development environment is in a Linux VM). So those must get converted
    > > from Unix to CRLF format if downloaded using a browser running on
    > > Windows.
    > > The majority of patch attachments (?) seem to have a Context-Type of
    > > "application/octet-stream" or "text/x-patch", and these seem to
    > > download raw (in their original Unix format).
    > 
    > Interesting.  I can probably adjust my MUA to send "text/x-patch",
    > but I'll have to look around to see where that's determined.
    > (I dislike using "application/octet-stream" for this, because
    > the archives won't show that as text, they only let you download
    > the attachment.  Maybe that's more Safari's fault than the
    > archives per se, not sure.)
    
    I would be interesting to know if "text/x-patch" is better than
    "text/x-diff" --- I currently use the later.
    
    -- 
      Bruce Momjian  <bruce@momjian.us>        https://momjian.us
      EDB                                      https://enterprisedb.com
    
      If only the physical world exists, free will is an illusion.
    
    
    
    
    
  23. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-11-30T21:35:13Z

    Bruce Momjian <bruce@momjian.us> writes:
    > On Mon, Nov 29, 2021 at 11:12:35PM -0500, Tom Lane wrote:
    >> Interesting.  I can probably adjust my MUA to send "text/x-patch",
    >> but I'll have to look around to see where that's determined.
    
    > I would be interesting to know if "text/x-patch" is better than
    > "text/x-diff" --- I currently use the later.
    
    I found out that where that is coming from is "file -i", so I'm a
    bit loath to modify it.  Is there any hard documentation as to why
    "text/x-patch" should be preferred?
    
    			regards, tom lane
    
    
    
    
  24. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Bruce Momjian <bruce@momjian.us> — 2021-11-30T21:52:31Z

    On Tue, Nov 30, 2021 at 04:35:13PM -0500, Tom Lane wrote:
    > Bruce Momjian <bruce@momjian.us> writes:
    > > On Mon, Nov 29, 2021 at 11:12:35PM -0500, Tom Lane wrote:
    > >> Interesting.  I can probably adjust my MUA to send "text/x-patch",
    > >> but I'll have to look around to see where that's determined.
    > 
    > > I would be interesting to know if "text/x-patch" is better than
    > > "text/x-diff" --- I currently use the later.
    > 
    > I found out that where that is coming from is "file -i", so I'm a
    > bit loath to modify it.  Is there any hard documentation as to why
    > "text/x-patch" should be preferred?
    
    I thought this was happening from /etc/mime.types:
    
    	text/x-diff                                     diff patch
    
    The file extensions 'diff' and 'patch' trigger mime to use text/x-diff
    for its attachments, at least on Debian.  Based on that, I assumed
    "text/x-diff" was more standardized than "text/x-patch".
    
    However, it seems file -i also looks at the contents since a file with a
    single word in it is not recognized as a diff:
    
    	$ git diff > /rtmp/x.diff
    	$ file -i /rtmp/x.diff
    	/rtmp/x.diff: text/x-diff; charset=us-ascii
    	              -----------
    	$ echo test > /rtmp/x.diff
    	$ file -i /rtmp/x.diff
    	/rtmp/x.diff: text/plain; charset=us-ascii
    	              ----------
    
    -- 
      Bruce Momjian  <bruce@momjian.us>        https://momjian.us
      EDB                                      https://enterprisedb.com
    
      If only the physical world exists, free will is an illusion.
    
    
    
    
    
  25. Re: Correct handling of blank/commented lines in PSQL interactive-mode history

    Tom Lane <tgl@sss.pgh.pa.us> — 2021-12-01T17:26:06Z

    Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
    > On 2021-Nov-29, Tom Lane wrote:
    >> After some further hackery, here's a set of patches that I think
    >> might be acceptable.  They're actually fairly independent, although
    >> they touch different aspects of the same behavior.
    
    > I tried the collection and I find the overall behavior quite convenient.
    > I think it works just as I wish it would.
    
    Hearing no further comments, pushed.
    
    			regards, tom lane