Re: Array value syntax and escaping - Mailing list pgsql-general

From Tom Lane
Subject Re: Array value syntax and escaping
Date
Msg-id 22396.1270154243@sss.pgh.pa.us
Whole thread Raw
In response to Array value syntax and escaping  (Peter Bex <Peter.Bex@xs4all.nl>)
Responses Re: Array value syntax and escaping  (Peter Bex <Peter.Bex@xs4all.nl>)
List pgsql-general
Peter Bex <Peter.Bex@xs4all.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

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: transaction control in pl/pgsql
Next
From: Szymon Guz
Date:
Subject: temporary table