pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedescaping characters ...
5+ messages / 4 participants
[nested] [flat]
* escaping characters ...
@ 2000-01-04 17:45 The Hermit Hacker <scrappy@hub.org>
0 siblings, 1 reply; 5+ messages in thread
From: The Hermit Hacker @ 2000-01-04 17:45 UTC (permalink / raw)
To: pgsql-interfaces
Vince and I are working on the UdmSearch engine for the web site, and keep
coming across minor "nits"...basically, it was originally designed under
MySQL and they've done preliminary porting to PostgreSQL, but its missing
some things :(
Comment from one of the developers:
===================
The question for PostgreSQL users.
MySQl has 'mysql_escape_string' in it's client library. Does Pg have
something like that? Sorry, we are not enough expirienced with
PostgreSQL.
===================
I've looked through our docs, and find nothing that appears similar ... do
we have something like this in our client library tht I'm not seeing?
if not, what should be escaped? The only thing that comes to mind is '
...
thanks...
Marc G. Fournier ICQ#7615664 IRC Nick: Scrappy
Systems Administrator @ hub.org
primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [INTERFACES] escaping characters ...
@ 2000-01-04 18:12 Tom Lane <tgl@sss.pgh.pa.us>
parent: The Hermit Hacker <scrappy@hub.org>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2000-01-04 18:12 UTC (permalink / raw)
To: The Hermit Hacker <scrappy@hub.org>; +Cc: pgsql-interfaces
The Hermit Hacker <scrappy@hub.org> writes:
> MySQl has 'mysql_escape_string' in it's client library. Does Pg have
> something like that?
libpq doesn't provide any such function --- perhaps it should, but
on the other hand the amount of code involved is pretty tiny, and
issues like memory allocation/freeing would complicate the definition
of the function.
> if not, what should be escaped?
When generating quoted strings for use in SQL commands, you should
prefix single-quote (') and backslash (\) characters with a backslash.
I think that's all.
COPY IN/OUT data has a different set of rules. There, you can but
don't have to backslash single quotes. You do need to convert returns
and tabs into \n and \t, and of course backslash itself must be doubled.
(If you are using some other character than tab as the field delimiter,
then it'd need backslashing instead.)
Data returned by libpq after a SELECT is not quoted at all.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [INTERFACES] escaping characters ...
@ 2000-01-04 19:53 Michael Meskes <meskes@postgresql.org>
0 siblings, 1 reply; 5+ messages in thread
From: Michael Meskes @ 2000-01-04 19:53 UTC (permalink / raw)
To: pgsql-interfaces
On Tue, Jan 04, 2000 at 01:12:58PM -0500, Tom Lane wrote:
> When generating quoted strings for use in SQL commands, you should
> prefix single-quote (') and backslash (\) characters with a backslash.
> I think that's all.
Isn't the correct way to quote a single-quote with yet another single-quote?
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De | Use PostgreSQL!
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [INTERFACES] escaping characters ...
@ 2000-01-04 21:43 Tom Lane <tgl@sss.pgh.pa.us>
parent: Michael Meskes <meskes@postgresql.org>
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2000-01-04 21:43 UTC (permalink / raw)
To: Michael Meskes <meskes@postgreSQL.org>; +Cc: pgsql-interfaces
Michael Meskes <meskes@postgreSQL.org> writes:
> On Tue, Jan 04, 2000 at 01:12:58PM -0500, Tom Lane wrote:
>> When generating quoted strings for use in SQL commands, you should
>> prefix single-quote (') and backslash (\) characters with a backslash.
> Isn't the correct way to quote a single-quote with yet another single-quote?
Yeah, doubled '' works too (but only in SQL literals, not in COPY data).
Take your pick...
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [INTERFACES] escaping characters ...
@ 2000-01-05 17:33 Joe Shevland <shevlandj@kpi.com.au>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Joe Shevland @ 2000-01-05 17:33 UTC (permalink / raw)
To: The Hermit Hacker <scrappy@hub.org>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces
What about: % and ? for like clauses... I think the function in question
would be a handy option though. I almost always implement one of these
methods in the application code.
Regards,
Joe Shevland
----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "The Hermit Hacker" <scrappy@hub.org>
Cc: <pgsql-interfaces@postgreSQL.org>
Sent: Tuesday, January 04, 2000 10:12 AM
Subject: Re: [INTERFACES] escaping characters ...
> The Hermit Hacker <scrappy@hub.org> writes:
> > MySQl has 'mysql_escape_string' in it's client library. Does Pg have
> > something like that?
>
> libpq doesn't provide any such function --- perhaps it should, but
> on the other hand the amount of code involved is pretty tiny, and
> issues like memory allocation/freeing would complicate the definition
> of the function.
>
> > if not, what should be escaped?
>
> When generating quoted strings for use in SQL commands, you should
> prefix single-quote (') and backslash (\) characters with a backslash.
> I think that's all.
>
> COPY IN/OUT data has a different set of rules. There, you can but
> don't have to backslash single quotes. You do need to convert returns
> and tabs into \n and \t, and of course backslash itself must be doubled.
> (If you are using some other character than tab as the field delimiter,
> then it'd need backslashing instead.)
>
> Data returned by libpq after a SELECT is not quoted at all.
>
> regards, tom lane
>
> ************
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2000-01-05 17:33 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-01-04 17:45 escaping characters ... The Hermit Hacker <scrappy@hub.org>
2000-01-04 18:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2000-01-05 17:33 ` Joe Shevland <shevlandj@kpi.com.au>
2000-01-04 19:53 Re: [INTERFACES] escaping characters ... Michael Meskes <meskes@postgresql.org>
2000-01-04 21:43 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox