Escaping \n

Started by Terry Lee Tuckerabout 18 years ago4 messagesgeneral
Jump to latest
#1Terry Lee Tucker
terry@chosen-ones.org

Greetings:

We are moving our application from 7.4.14 to 8.3.1. One giant step for
mankind...
Anyay, I have several triggers that update notes fields in certain tables and
loading the trigger function is giving me the following error:

psql:bill/bill_preupd_func.plsql:83: WARNING: nonstandard use of escape in a
string literal
LINE 1: ...OR REPLACE FUNCTION bill_preupd_func () RETURNS TRIGGER AS '
^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.

The problem is a line like 'UPDATE bill SET notes = 'blah, blah, yea\nmore
stuff';

How to I escape the newline embeded in the string? I've tried the advice from
HINT, but have been unable to get it to work.

Thanks...

Thanks...
--
Terry Lee Tucker
Turbo's IT Manager
Turbo, division of Ozburn-Hessey Logistics
2251 Jesse Jewell Pkwy NE
Gainesville, GA 30501
Tel: (336) 372-6812 Fax: (336) 372-6812 Cell: (336) 404-6987
terry@turbocorp.com
www.turbocorp.com

#2Sam Mason
sam@samason.me.uk
In reply to: Terry Lee Tucker (#1)
Re: Escaping \n

On Fri, Mar 28, 2008 at 05:06:10PM -0400, Terry Lee Tucker wrote:

HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.

The problem is a line like 'UPDATE bill SET notes = 'blah, blah, yea\nmore
stuff';

How to I escape the newline embeded in the string? I've tried the advice from
HINT, but have been unable to get it to work.

The statement would become:

UPDATE bill SET notes = E'blah, blah, yea\nmore stuff';

Is this what you tried? I couldn't tell from your message. If you did,
then maybe your database drivers are somehow mangling the statement
somewhere between your code and the database. You could try running it
locally from inside psql to find out.

Sam

#3Terry Lee Tucker
terry@chosen-ones.org
In reply to: Sam Mason (#2)
Re: Escaping \n

On Friday 28 March 2008 17:21, Sam Mason wrote:

On Fri, Mar 28, 2008 at 05:06:10PM -0400, Terry Lee Tucker wrote:

HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.

The problem is a line like 'UPDATE bill SET notes = 'blah, blah,
yea\nmore stuff';

How to I escape the newline embeded in the string? I've tried the advice
from HINT, but have been unable to get it to work.

The statement would become:

UPDATE bill SET notes = E'blah, blah, yea\nmore stuff';

Is this what you tried? I couldn't tell from your message. If you did,
then maybe your database drivers are somehow mangling the statement
somewhere between your code and the database. You could try running it
locally from inside psql to find out.

Sam

Thanks Sam. No, that is not what I tried. I had tried:
UPDATE bill SET notes = 'blah, blah, yeaE'\n'more stuff.'
It didn't dawn on me that the E went in front of the whole string!

Thanks for the help...
--
Terry Lee Tucker
Turbo's IT Manager
Turbo, division of Ozburn-Hessey Logistics
2251 Jesse Jewell Pkwy NE
Gainesville, GA 30501
Tel: (336) 372-6812 Fax: (336) 372-6812 Cell: (336) 404-6987
terry@turbocorp.com
www.turbocorp.com

#4Sam Mason
sam@samason.me.uk
In reply to: Terry Lee Tucker (#3)
Re: Escaping \n

On Fri, Mar 28, 2008 at 05:29:06PM -0400, Terry Lee Tucker wrote:

Thanks Sam. No, that is not what I tried. I had tried:
UPDATE bill SET notes = 'blah, blah, yeaE'\n'more stuff.'
It didn't dawn on me that the E went in front of the whole string!

it's always easy when you know how!

Thanks for the help...

No probs.

PG 8.3 is also more strict with its automatic casts and you may have
fun there as well. In previous versions, it would be reasonably happy
to (silently) convert lots of datatypes to text. This was generally
useful, but occasionally led to bad things happening. Most times I've
seen people affected by this is with dates---i.e. to get the year some
people did substr(datecol,1,4). In this case you should really be doing
extract(year from datecol) because the year doesn't always have to be in
the first four digits it just tends to be in the common setups.

Sam