Skip to content

Conversation

@lemonadern
Copy link
Collaborator

@lemonadern lemonadern commented Apr 28, 2025

Summary

insert_column_list, index_params, values_clause をフラット化しました

insert_column_list

insert 文のカラム名リストにあたる要素

-- `a, b, c` の部分が該当
INSERT INTO tbl (a, b, c) VALUES (1, 2, 3);
insert_column_list:
			insert_column_item
					{ $$ = list_make1($1); }
			| insert_column_list ',' insert_column_item
					{ $$ = lappend($1, $3); }
		;

https://github.com/postgres/postgres/blob/b225c5e76ed1053e505e392423b0dab065a3b813/src/backend/parser/gram.y#L12306-L12311

index_params

インデックス定義を複数並べる場合に利用される要素

-- insert では、 on conflict で登場
-- on conflict の後の a, b の部分が該当
INSERT INTO tbl (a, b, c) VALUES (1, 2, 3)
ON CONFLICT (a, b) DO NOTHING;
index_params:	index_elem							{ $$ = list_make1($1); }
			| index_params ',' index_elem			{ $$ = lappend($1, $3); }
		;

https://github.com/postgres/postgres/blob/b225c5e76ed1053e505e392423b0dab065a3b813/src/backend/parser/gram.y#L8267-L8269

values_clause

values 句で 複数の列を書く場合に入れ子になる要素
最も内側のものだけ values キーワードが挟まる点でほかのリストと異なる構造だが、フラット化しても問題なし

values (1,2,3), (4,5,6), (7,8,9);
values_clause:
			VALUES '(' expr_list ')'
				{
					SelectStmt *n = makeNode(SelectStmt);


					n->stmt_location = @1;
					n->valuesLists = list_make1($3);
					$$ = (Node *) n;
				}
			| values_clause ',' '(' expr_list ')'
				{
					SelectStmt *n = (SelectStmt *) $1;


					n->valuesLists = lappend(n->valuesLists, $4);
					$$ = (Node *) n;
				}
		;

https://github.com/postgres/postgres/blob/b225c5e76ed1053e505e392423b0dab065a3b813/src/backend/parser/gram.y#L13588-L13604

@lemonadern lemonadern marked this pull request as ready for review April 28, 2025 06:35
@lemonadern lemonadern changed the title flatten insert_column_list and index_params flatten insert_column_list ,index_params, and values_clause Apr 28, 2025
@tanzaku tanzaku merged commit d79e889 into main May 7, 2025
@lemonadern lemonadern deleted the tree-sitter--flatten-insert-column-list-and-index-params branch May 14, 2025 06:55
tanzaku added a commit that referenced this pull request Jul 15, 2025
* refactor

* add example

* update: README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants