Subject: | Postgres parser: Default value handling [patch] |
Hi there,
I have been taking a look at the default value handling as it was causing me a number of problems.
The regexp in the default value handling part of the grammar for the
postgres parser has a number of bugs. It does not handle strings such as
'[foo]' or 'foo bar' as it does not allow square brackets or spaces in
strings, (there are probably other valid characters which it disallows).
It also does not handle function calls such as nextval('foo')
where foo is a sequence name. I have thus come up with a new regexp
which checks for either a number or a single-quote delimited string or a
function call.
The current way:
default_val : /default/i /(?:')?[\w\d().-]*(?:')?/
My suggested method:
default_val : /default/i /(\d+|'[^']+'|\w+\(.*?\))/
With this change to allow sequence function calls the global removal of single-quotes cannot be used, so I suggest replacing:
$val =~ s/'//g;
with
$val =~ s/^'//; $val =~ s/'$//;
which just removes leading and trailing single-quotes, although I'm not sure this is needed at all.
It is also currently broken in the way it handles the values it finds via the regexp as the statement:
my $val = $item[2] || '';
means that when $item[2] is zero it evaluates to false and the value is replaced with an empty string. A safer method is:
my $val = defined $item[2] ? $item[2] : '';
Thanks,
Stephen Quinney
Message body not shown because it is not plain text.