File tree Expand file tree Collapse file tree 2 files changed +45
-21
lines changed
ccl/logictestccl/testdata/logic_test Expand file tree Collapse file tree 2 files changed +45
-21
lines changed Original file line number Diff line number Diff line change @@ -693,3 +693,40 @@ BEGIN
693
693
END IF;
694
694
END;
695
695
$$ LANGUAGE PLpgSQL;
696
+
697
+ subtest multi_declare
698
+
699
+ statement ok
700
+ DROP FUNCTION IF EXISTS f;
701
+
702
+ statement ok
703
+ CREATE FUNCTION f() RETURNS INT AS $$
704
+ DECLARE
705
+ x INT := 0;
706
+ DECLARE
707
+ y INT := x + 1;
708
+ BEGIN
709
+ RAISE NOTICE '% %', x, y;
710
+ RETURN 0;
711
+ END;
712
+ $$ LANGUAGE PLpgSQL;
713
+
714
+ query T noticetrace
715
+ SELECT f();
716
+ ----
717
+ NOTICE: 0 1
718
+
719
+ statement ok
720
+ DROP FUNCTION IF EXISTS f;
721
+
722
+ statement error pgcode 42601 pq: duplicate declaration at or near "x"
723
+ CREATE FUNCTION f() RETURNS INT AS $$
724
+ DECLARE
725
+ x INT := 0;
726
+ DECLARE
727
+ x INT := 1;
728
+ BEGIN
729
+ RAISE NOTICE '%', x;
730
+ RETURN 0;
731
+ END;
732
+ $$ LANGUAGE PLpgSQL;
Original file line number Diff line number Diff line change @@ -344,7 +344,7 @@ func (u *plpgsqlSymUnion) sqlStatement() tree.Statement {
344
344
%type <plpgsqltree.Statement> stmt_commit stmt_rollback
345
345
%type <plpgsqltree.Statement> stmt_case stmt_foreach_a
346
346
347
- %type <plpgsqltree.Statement> decl_stmt decl_statement
347
+ %type <plpgsqltree.Statement> decl_statement
348
348
%type <[]plpgsqltree.Statement> decl_sect opt_decl_stmts decl_stmts
349
349
350
350
%type <[]plpgsqltree.Exception> exception_sect proc_exceptions
@@ -419,36 +419,23 @@ opt_decl_stmts: decl_stmts
419
419
}
420
420
;
421
421
422
- decl_stmts : decl_stmts decl_stmt
422
+ opt_declare : DECLARE {}
423
+ | {}
424
+ ;
425
+
426
+ decl_stmts : decl_stmts opt_declare decl_statement
423
427
{
424
428
decs := $1 .statements()
425
- dec := $2 .statement()
429
+ dec := $3 .statement()
426
430
$$ .val = append(decs, dec)
427
431
}
428
- | decl_stmt
432
+ | decl_statement
429
433
{
430
434
dec := $1 .statement()
431
435
$$ .val = []plpgsqltree.Statement{dec}
432
436
}
433
437
;
434
438
435
- decl_stmt : decl_statement
436
- {
437
- $$ .val = $1 .statement()
438
- }
439
- | DECLARE
440
- {
441
- // This is to allow useless extra "DECLARE" keywords in the declare section.
442
- $$ .val = (plpgsqltree.Statement)(nil)
443
- }
444
- // TODO (drewk ): turn this block on and throw useful error if user
445
- // tries to put the block label just before BEGIN instead of before
446
- // DECLARE.
447
- //| LESS_LESS any_identifier GREATER_GREATER
448
- // {
449
- // }
450
- ;
451
-
452
439
decl_statement : decl_varname decl_const decl_datatype decl_collate decl_notnull decl_defval
453
440
{
454
441
$$ .val = &plpgsqltree.Declaration{
You can’t perform that action at this time.
0 commit comments