Thread: My problem upgrading to 8.0.0

My problem upgrading to 8.0.0

From
Dave Bodenstab
Date:
I upgraded from 7.1.3 to 8.0.0 and I find that almost every one of
my scripts which parse psql output are broken.  This is because of
the array output format change that, I believe, happened around 7.2.

I been using awk (and even /bin/sh) to parse psql's output and for 7.1.3
I was able to use three re's to split a character array into it's
components:

   sub( /^{"/, "", $n )
   sub( /"}$/, "", $n )
   split( $n, address, /","/ )

This will work for every case but one: when an element ended with
the two characters doublequote-comma.  As I know that none of my
data contains this, everything worked.

Now, elements in array output are only quoted if necessary.  This
means that re's cannot be used!  I have to write a character-by-character
parser in awk, sh (probably impossible), etc. and modify every script
that parses array output.

I didn't see any per-array option to set the element separator
character; it looks like I would have to change it for the database
as a whole.

I suppose I could write a post-processor in C and filter all the output
of psql thru that; perhaps such a thing already exists?

I looked at postgresql's source -- I guess I could force all elements
to be quoted again for my installation.

I can sort of get what I want by:

   select '{"' || array_to_string(v,'","') || '"}' from ...

but this has many more cases where the data within the array affects
parsing.  Array_to_string removes all backslashes so now any string
containing the three characters "," will be inappropriately split.
I don't think any of my data has this, but it would make the scripts
much more vulnerable to breakage in the future.


I am hoping that this issue came up back when the array output was
changed.  I could not find any reference on Google or postgresql.org
but I probably am not phrasing my queries well enough.  If this was
an issue when array output changed, can anyone point me at some possible
solutions that hopefully don't require me to rewrite all of my
scripts?  Or techniques used to parse psql output containing array
output using awk or sh?

Thanks.

Dave Bodenstab