Re: #escape_string_warning = off

From: Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>
To: Jeff Davis <jdavis-pgsql(at)empires(dot)org>
Cc: Marko Kreen <marko(at)l-t(dot)ee>, "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: #escape_string_warning = off
Date: 2005-08-02 08:35:17
Message-ID: Pine.LNX.4.44.0508021027140.2995-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 2 Aug 2005, Jeff Davis wrote:

> >>Does the SQL standard provide no way to have a NULL character in a
> >>string constant? Is single-quote the only special character?
> >
> > I don't think it forbids you from using the null character. It's not like
> > the strings are zero terminated. Some encodings might not allow the null
> > character, but that's different.
>
> But doesn't PostgreSQL forbid us from using the NULL character in a
> query at all? Don't we always have to escape or encode it in some way?

Pg does not allow \0 in strings at all. Try SELECT 'abc\0def'; in the
current version of pg.

The sql standard doesn't forbid null values in strings as far as I know
and that's all I talked about. To have a sql standard string with null
inside you just insert the 0 byte (for normal single byte encodings), no
escaping needed.

Internally pg handles strings as \0-terminated entities which is a bit
unfortunate but that's what we have. That's why 'abc\0def' became the
string 'abc'. Most character sets forbid \0 in strings anyway.

--
/Dennis Björklund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas F. O'Connell 2005-08-02 16:16:30 Re: bgwriter, inherited temp tables TODO items?
Previous Message Jeff Davis 2005-08-02 07:57:34 Re: #escape_string_warning = off