pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Eli Bingham <eli@savagebeast.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [7.4.6] Escaping strings in text arrays passed through
Date: Thu, 16 Dec 2004 21:57:01 -0500 (EST)
Message-ID: <Pine.BSO.4.56.0412162147330.8739@leary.csoft.net> (raw)
In-Reply-To: <4D818F9B-4FD4-11D9-A381-000D932A4B80@savagebeast.com>
References: <4D818F9B-4FD4-11D9-A381-000D932A4B80@savagebeast.com>



On Thu, 16 Dec 2004, Eli Bingham wrote:

> CallableStatement stmt = conn.prepareCall ("{ ? = call do_stuff 
> (?::text[]) }";
> stmt.registerOutParameter (1, Types.INTEGER);
> stmt.setObject (2, "{x, y, z}")
> 
> But what can I do when one of the input strings x, y, or z has a comma 
> in it?  How can I escape the comma so that the stored procedure will 
> still see a text array of three elements?

You can either use the ARRAY constructor:

jurka=# SELECT ARRAY['x, ', 'y', 'z'];
    array
-------------
 {"x, ",y,z}

or notice how the above added the quotes around the first value, this is 
also legal input syntax:

jurka=# SELECT '{"x, ",y,z}::text[];
    text
-------------
 {"x, ",y,z}

This natural leads to how do you escape quotes?  Which is answered by:

jurka=# SELECT ARRAY['"','a'];
    array
------------
 {"\"",a}


For all the details, see: 

http://www.postgresql.org/docs/7.4/static/arrays.html#AEN5261

Kris Jurka



view thread (2+ messages)

Message-ID: <Pine.BSO.4.56.0412162147330.8739@leary.csoft.net>
Permalink:  ../Pine.BSO.4.56.0412162147330.8739@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.56.0412162147330.8739@leary.csoft.net

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: books@ejurka.com, eli@savagebeast.com
  Subject: Re: [7.4.6] Escaping strings in text arrays passed through
  In-Reply-To: <Pine.BSO.4.56.0412162147330.8739@leary.csoft.net>
  References: <4D818F9B-4FD4-11D9-A381-000D932A4B80@savagebeast.com> <Pine.BSO.4.56.0412162147330.8739@leary.csoft.net>

* 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