Re: newline conversion in SQL command strings - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: newline conversion in SQL command strings
Date
Msg-id 505B6D38.5080203@dunslane.net
Whole thread Raw
In response to Re: newline conversion in SQL command strings  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: newline conversion in SQL command strings  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 09/20/2012 09:12 AM, Peter Eisentraut wrote:
> On 9/20/12 2:01 AM, Heikki Linnakangas wrote:
>> Could you strip the CRs? Either at CREATE FUNCTION time, or when the
>> function is executed.
> It has been proposed that the plsh handler should strip the CRs before
> execution.  But I don't think that is a correct solution, because that
> is user data which could be relevant.  It could be the case, for
> example, that plsh is run on a Windows host with a particular shell that
> requires CRLF line endings.
>
>

I confess I find it hard to take plsh terribly seriously, it just seems 
like a bad solution for practically any problem, when compared with, 
say, plperlu, and it seems so Unixish that the very idea of using it at 
all on Windows strikes me as crazy. Having said that, and devoted all of 
5 minutes to looking at the code, I suggest that you make two changes:
       if (sourcecode[0] == '\n')           sourcecode++;

would become:
       if (sourcecode[0] == '\n' || (sourcecode[0] == '\r' && sourcecode[1] == '\n'))           sourcecode++;

and
       len = strcspn(rest, "\n");

would become:
       len = strcspn(rest, "\r\n");



Also, there is probably a pretty good case for opening the temp file using PG_BINARY_W rather than "w" so that Windows
doesn'tproduce extra CRs for you (see recent discussion of this w.r.t. pg_upgrade).
 


cheers

andrew





pgsql-hackers by date:

Previous
From: Kohei KaiGai
Date:
Subject: Re: Move postgresql_fdw_validator into dblink
Next
From: Tom Lane
Date:
Subject: Re: newline conversion in SQL command strings