Re: newline conversion in SQL command strings

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: newline conversion in SQL command strings
Date: 2012-09-20 19:23:36
Message-ID: 505B6D38.5080203@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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't produce extra CRs for you (see recent discussion of this w.r.t. pg_upgrade).

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2012-09-20 19:34:19 Re: newline conversion in SQL command strings
Previous Message Kohei KaiGai 2012-09-20 19:18:12 Re: Move postgresql_fdw_validator into dblink