-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgresql-grammar.ebnf
30 lines (24 loc) · 1.54 KB
/
postgresql-grammar.ebnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
select keyword = ('S' | 's'), ('E' | 'e'), ('L' | 'l'), ('E' | 'e'), ('C' | 'c'), ('T' | 't');
from keyword = ('F' | 'f'), ('R' | 'r'), ('O' | 'o'), ('M' | 'm');
whitespace char = (' ' | '\n' | '\t');
whitespace = whitespace char, {whitespace char};
optional whitespace = {whitespace char};
unquoted identifier = ('_' | alphabetic char), {('_' | '$' | alphabetic char | digit)};
alphabetic char = ? any character a-z or A-Z or with a diacritic or non-latin letters ?;
digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
quoted identifier = '"', any character, {any character}, '"';
# Note this is literally any character, including things like newlines
# You can, in fact, have an identifier with a newline.
any character = ? any character ?
identifier = (unquoted identifier | quoted identifier);
statement end = ';';
input = { optional whitespace, command, optional whitespace };
command = data manipulation command;
data manipulation command = select command;
select command = select keyword, whitespace, selected expressions, whitespace, from keyword, whitespace, from item, optional whitespace, statement end;
all columns selected expression = [identifier, '.'], [identifier, '.'], '*';
column selected expression = [identifier, '.'], [identifier, '.'], identifier;
selected expression = (all columns selected expression | column selected expression);
# For now, >= 1 expression is needed
selected expressions = selected expression, optional whitespace, {',', optional whitespace, selected expression};
from item = [identifier, '.'], identifier;