bug fixes

This commit is contained in:
Christian De la Hoz 2021-09-02 20:45:02 +02:00
parent a4cbb1ab05
commit 7beede0306
4 changed files with 58 additions and 5 deletions

View file

@ -85,12 +85,45 @@ CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql VOLATILE;
(identifier) (identifier)
(function_volatility))) (function_volatility)))
================================================================================
returns array
================================================================================
CREATE FUNCTION FOO () RETURNS text[] AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(string)
(identifier)))
================================================================================ ================================================================================
returns setof returns setof
================================================================================ ================================================================================
CREATE FUNCTION FOO () RETURNS SETOF text AS 'select' LANGUAGE sql; CREATE FUNCTION FOO () RETURNS SETOF text AS 'select' LANGUAGE sql;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(return_setof
(identifier)))
(string)
(identifier)))
================================================================================
returns setof array
================================================================================
CREATE FUNCTION FOO () RETURNS SETOF text[] AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file (source_file
(create_function_statement (create_function_statement
(function_signature (function_signature

View file

@ -141,7 +141,7 @@ do $$ begin
execute format( execute format(
$sql$ $sql$
update %1$s update %1$s
set foo = $1 set foo = $1, %2$I = $1
$sql$ $sql$
, _tbl_name) using bar; , _tbl_name) using bar;
end $$; end $$;

View file

@ -78,6 +78,25 @@ insert from select
insert into foo.my_table select column1 from foo bar; insert into foo.my_table select column1 from foo bar;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier)
(identifier))))))))
================================================================================
insert from select(1)
================================================================================
insert into foo.my_table (select column1 from foo bar);
--------------------------------------------------------------------------------
(source_file (source_file
(insert_statement (insert_statement
(identifier) (identifier)

View file

@ -114,7 +114,8 @@ module.exports = grammar({
insert_items: $ => choice( insert_items: $ => choice(
seq(kw("default"), kw("values")), seq(kw("default"), kw("values")),
seq(kw("values"), "(", commaSep($.insert_item), ")"), seq(kw("values"), "(", commaSep($.insert_item), ")"),
$.select_statement $.select_statement,
seq("(", $.select_statement, ")"),
), ),
insert_item: $ => choice( insert_item: $ => choice(
kw("default"), kw("default"),
@ -605,12 +606,12 @@ module.exports = grammar({
function_return: $ => seq( function_return: $ => seq(
kw("returns"), kw("returns"),
choice( choice(
$.identifier, $._type,
$.return_setof, $.return_setof,
$.return_table, $.return_table,
), ),
), ),
return_setof: $ => seq(kw("setof"), $.identifier), return_setof: $ => seq(kw("setof"), $._type),
return_table: $ => seq(kw("table"), "(", commaSep1($.var_declaration), ")"), return_table: $ => seq(kw("table"), "(", commaSep1($.var_declaration), ")"),
function_volatility: $ => choice( function_volatility: $ => choice(
@ -755,7 +756,7 @@ module.exports = grammar({
// TODO(chrde): it does not handle nested dollar quotes... perhaps move to an external scanner? // TODO(chrde): it does not handle nested dollar quotes... perhaps move to an external scanner?
dollar_quote_string: $ => seq( dollar_quote_string: $ => seq(
"$", $._identifier, "$", "$", $._identifier, "$",
/(([^$]+)|(%\d+\$s)|(\$\d+))+/, /(([^$]+)|(%\d+\$[sI])|(\$\d+))+/,
// ^ // ^
// |- matches $1 (execute ... using placeholders) // |- matches $1 (execute ... using placeholders)
// ^ // ^