escape string type for upcoming 8.1 - Mailing list pgsql-general

From Jeff Davis
Subject escape string type for upcoming 8.1
Date
Msg-id 42F7AB43.9030906@empires.org
Whole thread Raw
Responses Re: escape string type for upcoming 8.1  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-general
From what I've read, it looks like 8.1 will introduce the E'' escape
string, and eventually postgresql will change the normal '' strings to
be more SQL-compliant.

If I wanted to start being forwards-compatible right now, and I have
existing databases in 7.4 and 8.0, my idea was to create a type E. Any
string using that type would work in 7.4/8.0 as normal, and then when I
upgrade to 8.1 I will drop the type and the applications will still work.

To do that is relatively simple, I'd just use the textin/out functions
that already exist to create the type (which in 7.4/8.0 will give the
desired behavior of escaping). Like so:

CREATE FUNCTION ein(CSTRING) RETURNS E AS 'textin' LANGUAGE internal;

CREATE FUNCTION eout(E) RETURNS CSTRING AS 'textout' LANGUAGE internal;

CREATE TYPE E (input=ein,output=eout);

CREATE CAST (E AS TEXT) WITHOUT FUNCTION AS IMPLICIT;

CREATE CAST (TEXT AS E) WITHOUT FUNCTION AS IMPLICIT;

Then, when I upgrade a system to 8.1, I can just remove the type, and
all the applications will still work. Eventually when the '' strings are
changed, I can start using those again, but in a SQL-compliant way.

Does this migration path make sense? Will creating the type possibly
cause casting problems of some kind? I read something about possibly
"backpatching" the E'' string to 8.0. If someone did that, what would be
the difference between applying a backpatch and what I did above?

One thing that has me concerned about the idea is that there are some
string constants, like B'' and X'' that aren't really types. Does that
mean that E'' won't be a type? Why are B'' and X'' not types, and are
there any other notations like that that are not types?

Regards,
    Jeff Davis

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: PL/pgSQL in 8.0
Next
From: Tony Caduto
Date:
Subject: Simple PG Sql question (i hope)