Re: Array value syntax and escaping

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Bex <Peter(dot)Bex(at)xs4all(dot)nl>
Cc: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Array value syntax and escaping
Date: 2010-04-01 20:37:23
Message-ID: 22396.1270154243@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter Bex <Peter(dot)Bex(at)xs4all(dot)nl> writes:
> I am currently adding array value handling to the PostgreSQL interface
> for the Chicken Scheme compiler[*] and I was wondering if there's a more
> detailed documentation for the exact syntax of arrays than the short
> natural language explanation in the manual.

There is not, but you could always look at the source for array_out and
array_in if you want definitive answers ;-). Personally what I'd do is
always double-quote each non-null array element; then the rules reduce
to "backslash any backslashes or double quotes". If you're working in
a sane client encoding (not SJIS for instance) this is pretty trivial.

> IMHO, it would be a Good Thing to have helper procedures in libpq.

The problem with that is that the necessarily-arbitrary API would
probably add as much or more complexity as would be saved. If C had
a simple and universally-followed convention for variable-size arrays,
it'd be easier to provide useful helpers ...

> I briefly considered "abusing" the PQescapeIdentifier procedure for
> escaping since the syntax for literals inside arrays seems to be exactly
> like that of SQL identifiers, but I'm not 100% sure about that and I
> also think the PQescapeIdentifier procedure shouldn't be overloaded for
> this purpose.

Well, that wouldn't work anyway, since backslashes aren't special in
identifiers.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Szymon Guz 2010-04-01 20:44:06 temporary table
Previous Message Merlin Moncure 2010-04-01 20:33:17 Re: transaction control in pl/pgsql