Re: standard_conforming_strings and pg_escape_string()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Conrad Lender <crlender(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: standard_conforming_strings and pg_escape_string()
Date: 2009-04-23 22:56:33
Message-ID: 6570.1240527393@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Conrad Lender <crlender(at)gmail(dot)com> writes:
> I'm using PostgreSQL 8.3 with PHP's "pgsql" module (libpq 8.3.7). When
> the server's standard_conforming_strings setting is off (this is
> currently still the default, I believe), I use something like this to
> escape strings:

> if ($escWildcards) {
> $str = strtr($str, array("%" => '\%', "_" => '\_'));
> }
> return "E'" . pg_escape_string($str) . "'";

The above cannot possibly work. pg_escape_string is generating what it
supposes to be a normal string literal, and then you are sticking an 'E'
on the front which changes the escaping rules. It is not the function's
fault that this fails.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Conrad Lender 2009-04-23 23:12:26 Re: standard_conforming_strings and pg_escape_string()
Previous Message Adam Ruth 2009-04-23 22:51:40