Escaping

From: Maciek Sakrejda <msakrejda(at)truviso(dot)com>
To: PG-JDBC Mailing List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Escaping
Date: 2010-09-21 15:55:43
Message-ID: AANLkTikFQco_q1mK32XHPf6WJxTR_DTZ8_f5Wo9MzDxf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I need to format some data as text (since it's going into a textual
COPY), and I'm having a hard time escaping the input. My target column
is an array of UDTs. The UDTs are composed of two integers and an
hstore (yes, relational algebra weeps at what I'm doing). With the
ARRAY[ ... ] notation, this is fairly straightforward.

cqdb=# create type foo as (a int, b int, c hstore);
CREATE TYPE
cqdb=# select (ARRAY[ (1,2,E'foo=>bar,"=>\\""=>quux')::foo,
(3,4,'baz=>xyzzy')::foo ])::foo[];
array
-----------------------------------------------------------------------------------------------------------------
{"(1,2,\"\"\"=>\\\\\"\"\"\"=>\"\"quux\"\",
\"\"foo\"\"=>\"\"bar\"\"\")","(3,4,\"\"\"baz\"\"=>\"\"xyzzy\"\"\")"}
(1 row)

However, in order to feed this in as text, I need to use the array
literal notation and the way the escaping stacks is lost on me. I've
read the UDT docs, the array input docs, and the hstore input docs,
but somewhere my logic is going south. My standard_conforming_strings
is off, for what it's worth.

Anyway, to get to the JDBC part of this: are there utility functions
in the JDBC code that can help with this? It seems like escaping is a
relatively common scenario, but I don't see anything relevant except
for Utils.appendEscapedLiteral(), which doesn't seem quite what I'm
looking for (it does not deal with double quotes).

Thanks,
---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kevin Grittner 2010-09-25 02:28:30 Re: Mapping Hibernate boolean to smallint(Postgresql)
Previous Message Devrim GÜNDÜZ 2010-09-21 07:30:28 Re: 9.0 JDBC drivers