From: Josh Berkus <josh@agliodbs.com>
To: pgsql-sql@postgresql.org
To: pgsql-hackers@postgresql.org
Subject: Request for builtin function: Double_quote
Date: Mon, 17 Jun 2002 13:34:01 -0700
Message-ID: <200206171334.01532.josh@agliodbs.com> (raw)
Folks,
Given the amount of qoute nesting we do in Postgres, I thought that we need a
function that handles automatic doubling of quotes within strings. I've
written one in PL/pgSQL (below). I'd really love to see this turned into a
builtin C function.
-Josh
CREATE FUNCTION double_quote(text) returns text as '
DECLARE bad_string ALIAS for $1;
good_string text;
current_pos INT;
old_pos INT;
BEGIN
IF bad_string IS NULL or bad_string = '''' THEN
RETURN bad_string;
END IF;
good_string := bad_string;
current_pos := STRPOS(good_string, chr(39));
WHILE current_pos > 0 LOOP
old_pos := current_pos;
good_string := SUBSTR(good_string, 1, (current_pos - 1)) ||
repeat(chr(39), 2) || SUBSTR(good_string, (current_pos
+ 1));
current_pos := STRPOS(SUBSTR(good_string, (old_pos + 2)),
chr(39));
IF current_pos > 0 THEN
current_pos := current_pos + old_pos + 1;
END IF;
END LOOP;
RETURN good_string;
END;'
LANGUAGE 'plpgsql'
WITH (ISCACHABLE, ISSTRICT);
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, pgsql-hackers@postgresql.org
Subject: Re: Request for builtin function: Double_quote
In-Reply-To: <200206171334.01532.josh@agliodbs.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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