Thread: Does Postgres replace \\ with \ in an update query

Does Postgres replace \\ with \ in an update query

From
"Vaughn Cleminson"
Date:
Hi All

I am doing a normal SQL update against postgres.
Seems to be replacing \\ with \ when it gets saved in the database. eg.
\\machine\folder is being replaced with \machine

Any ideas?

Vaughn




Re: Does Postgres replace \\ with \ in an update query

From
Richard Huxton
Date:
On Friday 15 Nov 2002 7:23 am, Vaughn Cleminson wrote:
> Hi All
>
> I am doing a normal SQL update against postgres.
> Seems to be replacing \\ with \ when it gets saved in the database. eg.
> \\machine\folder is being replaced with \machine
>
> Any ideas?

The backslash (\) character is used to escape other characters from normal
interpretation, so you can have a text value: 'Richard\'s text' which means
during processing the backslash is removed.

If you want to actually have a backslash in your sql you'll need to escape it
too. So you'll have something like:

INSERT INTO foo (path) VALUES ('\\\\machine\\folder');

Most application languages offer something like a quote_sql() function which
handles all the details of this for you.

--  Richard Huxton