Invalid YAML output from EXPLAIN

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Invalid YAML output from EXPLAIN
Date: 2010-06-07 08:14:43
Message-ID: AANLkTil525jVtk6q21jfR8Z-hb-7fT20P8Q_undvBbPb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Testing 9.0 beta, I found that EXPLAINing certain queries in YAML
format will produce invalid YAML, for example:

explain (format yaml) select * from foo where str_val = 'a: b';

The problem in this case is that a colon followed by whitespace is not
allowed in an unquoted plain YAML string because a parser would
interpret it as the start of a map.

So the current code in escape_yaml() is inadequate for producing valid
YAML. I think it would have to also consider at least the following
characters as special "-" ":" "[" "]" "{" "}" "," "\"" "'"
"|" "*" "&". Technically, it would also need to trap empty strings,
and strings with leading or trailing whitespace.

Making escape_yaml() completely bulletproof with this approach would
be quite difficult, and (IMO) not worth the effort, especially given
that an important requirement is that the output be machine readable,
and in my experience YAML parsers are often far from perfect.

I would therefore argue for simply calling escape_json() to produce
double quoted output for all string values, and only have numeric
values unquoted. This is not really any less human readable, and is
far more machine readable.

Patch attached.

- Dean

Attachment Content-Type Size
explain_yaml.patch text/x-patch 2.3 KB

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Dimitri Fontaine 2010-06-07 08:20:49 Re: Re: BUG #5490: Using distinct for select list causes insert of timestamp string literal to fail
Previous Message Craig Ringer 2010-06-07 03:17:07 Re: BUG #5490: Using distinct for select list causes insert of timestamp string literal to fail

Browse pgsql-hackers by date

  From Date Subject
Next Message Dimitri Fontaine 2010-06-07 08:14:47 Re: exporting raw parser
Previous Message KaiGai Kohei 2010-06-07 07:30:30 Re: [PATCH] Fix leaky VIEWs for RLS