Re: newline conversion in SQL command strings

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: newline conversion in SQL command strings
Date: 2012-09-20 06:01:28
Message-ID: 505AB138.9090307@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 20.09.2012 05:56, Peter Eisentraut wrote:
> I have received a number of bug reports about plsh choking on
> Windows-style line endings. The problem is that the user uses some
> Windows-based tool or other to execute an SQL command line this:
>
> CREATE FUNCTION foo() RETURNS something<CR><LF>
> LANGUAGE plsh<CR><LF>
> AS $$<CR><LF>
> #!/bin/sh<CR><LF>
> <CR><LF>
> do something<CR><LF>
> do something<CR><LF>
> $$;<CR><LF>
>
> which (apparently, I don't have Windows handy) creates a function with
> the prosrc body of
>
> '<CR><LF>
> #!/bin/sh<CR><LF>
> <CR><LF>
> do something<CR><LF>
> do something<CR><LF>
> '
>
> But executing this fails because Unix shells reject<CR> characters in
> inappropriate places as syntax errors.
>
> I don't know how to handle that. It would be unfortunate to have the
> behavior of a function depend on the kind of client used to create or
> modify it.

Could you strip the CRs? Either at CREATE FUNCTION time, or when the
function is executed.

- Heikki

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2012-09-20 07:54:25 Re: Fwd: PATCH: psql boolean display
Previous Message Amit Kapila 2012-09-20 05:10:23 Re: [v9.3] Extra Daemons (Re: elegant and effective way for running jobs inside a database)