Skip to content

feat(postgre): #412 update merge's syntax, with clause syntax and copy syntax #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/grammar/postgresql/PostgreSqlLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ KW_EXTENDED : 'EXTENDED';
KW_MAIN : 'MAIN';
KW_SKIP_LOCKED : 'SKIP_LOCKED';
KW_BUFFER_USAGE_LIMIT : 'BUFFER_USAGE_LIMIT';

KW_FORCE_QUOTE : 'FORCE_QUOTE';
KW_FORCE_NOT_NULL : 'FORCE_NOT_NULL';
KW_FORCE_NULL : 'FORCE_NULL';
//

// IDENTIFIERS (4.1.1)
Expand Down
17 changes: 15 additions & 2 deletions src/grammar/postgresql/PostgreSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ copystmt
) KW_WITH? copy_options
;

copy_options
copy_options_noparens
: (
KW_BINARY
| KW_FREEZE
Expand All @@ -569,8 +569,17 @@ copy_options
| KW_FORCE KW_QUOTE (column_list | STAR)
| KW_FORCE KW_NOT? KW_NULL column_list
| KW_ENCODING sconst
| (KW_FORCE_QUOTE | KW_FORCE_NOT_NULL | KW_FORCE_NULL) (
OPEN_PAREN (column_list | STAR) (COMMA (column_list | STAR))* CLOSE_PAREN
)?
)*
| OPEN_PAREN copy_generic_opt_elem (COMMA copy_generic_opt_elem)* CLOSE_PAREN
;

copy_options
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要使用下划线了吧,我在 spelling 的那个分支全部更改了PG,使用小驼峰写法

: copy_options_noparens
| OPEN_PAREN (copy_options_noparens | copy_generic_opt_elem) (
COMMA (copy_options_noparens | copy_generic_opt_elem)
)* CLOSE_PAREN
;

copy_generic_opt_elem
Expand Down Expand Up @@ -1911,11 +1920,13 @@ prep_type_clause
: OPEN_PAREN typename (COMMA typename)* CLOSE_PAREN
;

// https://www.postgresql.org/docs/17/sql-select.html
preparablestmt
: selectstmt
| insertstmt
| updatestmt
| deletestmt
| mergestmt
;

executestmt
Expand Down Expand Up @@ -3558,8 +3569,10 @@ stmt_move
: KW_MOVE opt_fetch_direction? cursor_variable SEMI
;

// https://www.postgresql.org/docs/17/sql-merge.html
mergestmt
: with_clause? KW_MERGE KW_INTO (KW_ONLY)? table_name (STAR)? (KW_AS? colid)? KW_USING data_source KW_ON expression merge_when_clause+
returning_clause?
;

data_source
Expand Down
11 changes: 10 additions & 1 deletion src/lib/postgresql/PostgreSqlLexer.interp

Large diffs are not rendered by default.

94 changes: 50 additions & 44 deletions src/lib/postgresql/PostgreSqlLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -546,48 +546,51 @@ KW_EXTENDED=545
KW_MAIN=546
KW_SKIP_LOCKED=547
KW_BUFFER_USAGE_LIMIT=548
Identifier=549
QuotedIdentifier=550
UnterminatedQuotedIdentifier=551
InvalidQuotedIdentifier=552
InvalidUnterminatedQuotedIdentifier=553
UnicodeQuotedIdentifier=554
UnterminatedUnicodeQuotedIdentifier=555
InvalidUnicodeQuotedIdentifier=556
InvalidUnterminatedUnicodeQuotedIdentifier=557
StringConstant=558
UnterminatedStringConstant=559
UnicodeEscapeStringConstant=560
UnterminatedUnicodeEscapeStringConstant=561
BeginDollarStringConstant=562
BinaryStringConstant=563
UnterminatedBinaryStringConstant=564
InvalidBinaryStringConstant=565
InvalidUnterminatedBinaryStringConstant=566
HexadecimalStringConstant=567
UnterminatedHexadecimalStringConstant=568
InvalidHexadecimalStringConstant=569
InvalidUnterminatedHexadecimalStringConstant=570
Integral=571
NumericFail=572
Numeric=573
PLSQLVARIABLENAME=574
PLSQLIDENTIFIER=575
Whitespace=576
Newline=577
LineComment=578
BlockComment=579
UnterminatedBlockComment=580
MetaCommand=581
EndMetaCommand=582
ErrorCharacter=583
EscapeStringConstant=584
UnterminatedEscapeStringConstant=585
InvalidEscapeStringConstant=586
InvalidUnterminatedEscapeStringConstant=587
DollarText=588
EndDollarStringConstant=589
AfterEscapeStringConstantWithNewlineMode_Continued=590
KW_FORCE_QUOTE=549
KW_FORCE_NOT_NULL=550
KW_FORCE_NULL=551
Identifier=552
QuotedIdentifier=553
UnterminatedQuotedIdentifier=554
InvalidQuotedIdentifier=555
InvalidUnterminatedQuotedIdentifier=556
UnicodeQuotedIdentifier=557
UnterminatedUnicodeQuotedIdentifier=558
InvalidUnicodeQuotedIdentifier=559
InvalidUnterminatedUnicodeQuotedIdentifier=560
StringConstant=561
UnterminatedStringConstant=562
UnicodeEscapeStringConstant=563
UnterminatedUnicodeEscapeStringConstant=564
BeginDollarStringConstant=565
BinaryStringConstant=566
UnterminatedBinaryStringConstant=567
InvalidBinaryStringConstant=568
InvalidUnterminatedBinaryStringConstant=569
HexadecimalStringConstant=570
UnterminatedHexadecimalStringConstant=571
InvalidHexadecimalStringConstant=572
InvalidUnterminatedHexadecimalStringConstant=573
Integral=574
NumericFail=575
Numeric=576
PLSQLVARIABLENAME=577
PLSQLIDENTIFIER=578
Whitespace=579
Newline=580
LineComment=581
BlockComment=582
UnterminatedBlockComment=583
MetaCommand=584
EndMetaCommand=585
ErrorCharacter=586
EscapeStringConstant=587
UnterminatedEscapeStringConstant=588
InvalidEscapeStringConstant=589
InvalidUnterminatedEscapeStringConstant=590
DollarText=591
EndDollarStringConstant=592
AfterEscapeStringConstantWithNewlineMode_Continued=593
'$'=1
'('=2
')'=3
Expand Down Expand Up @@ -1134,5 +1137,8 @@ AfterEscapeStringConstantWithNewlineMode_Continued=590
'MAIN'=546
'SKIP_LOCKED'=547
'BUFFER_USAGE_LIMIT'=548
'\\\\'=582
'\''=590
'FORCE_QUOTE'=549
'FORCE_NOT_NULL'=550
'FORCE_NULL'=551
'\\\\'=585
'\''=593
Loading