Skip to content

Derived table syntax allows dangling AS #7574

@mrotteveel

Description

@mrotteveel

The current syntax for derived tables allows a dangling AS, which should not be allowed. For example:

select *
from (
  select 1 as X from rdb$database
) as

This is the result of the syntax:

%type <selectExprNode> derived_table
derived_table
	: '(' select_expr ')' as_noise correlation_name derived_column_list
		{
			$$ = $2;
			$$->dsqlFlags |= RecordSourceNode::DFLAG_DERIVED;
			if ($5)
				$$->alias = $5->c_str();
			$$->columns = $6;
		}
	;

%type <metaNamePtr> correlation_name
correlation_name
	: /* nothing */				{ $$ = NULL; }
	| symbol_table_alias_name
	;

I think the correct syntax should be:

%type <selectExprNode> derived_table
derived_table
	: '(' select_expr ')' correlation_name derived_column_list
		{
			$$ = $2;
			$$->dsqlFlags |= RecordSourceNode::DFLAG_DERIVED;
			if ($5)
				$$->alias = $5->c_str();
			$$->columns = $6;
		}
	;

%type <metaNamePtr> correlation_name
correlation_name
	: /* nothing */				{ $$ = NULL; }
	| as_noise symbol_table_alias_name
	;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions