Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 189EA4762F7; Mon, 17 Jun 2002 16:36:18 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 3C0A9475E38; Mon, 17 Jun 2002 16:32:30 -0400 (EDT) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1530624; Mon, 17 Jun 2002 13:32:30 -0700 Content-Type: text/plain; charset="us-ascii" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: pgsql-sql@postgresql.org, pgsql-hackers@postgresql.org Subject: Request for builtin function: Double_quote Date: Mon, 17 Jun 2002 13:34:01 -0700 X-Mailer: KMail [version 1.4] MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200206171334.01532.josh@agliodbs.com> X-Archive-Number: 200206/222 X-Sequence-Number: 8187 Folks, Given the amount of qoute nesting we do in Postgres, I thought that we need= a=20 function that handles automatic doubling of quotes within strings. I've= =20 written one in PL/pgSQL (below). I'd really love to see this turned into a= =20 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 =3D '''' THEN RETURN bad_string; END IF; good_string :=3D bad_string; current_pos :=3D STRPOS(good_string, chr(39)); WHILE current_pos > 0 LOOP old_pos :=3D current_pos; good_string :=3D SUBSTR(good_string, 1, (current_pos - 1)) = || repeat(chr(39), 2) || SUBSTR(good_string, (current_= pos=20 + 1)); current_pos :=3D STRPOS(SUBSTR(good_string, (old_pos + 2)),= =20 chr(39)); IF current_pos > 0 THEN current_pos :=3D current_pos + old_pos + 1; END IF; END LOOP; RETURN good_string; END;' LANGUAGE 'plpgsql' WITH (ISCACHABLE, ISSTRICT);