From 324684a966d54b6c5f270443bf1a8e06e3bf9736 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Thu, 31 Aug 2023 20:01:33 +0300 Subject: [PATCH 1/3] Reduce MariaDB keywords list to only reserved ones --- src/languages/mariadb/mariadb.keywords.ts | 454 +--------------------- test/mariadb.test.ts | 24 ++ 2 files changed, 34 insertions(+), 444 deletions(-) diff --git a/src/languages/mariadb/mariadb.keywords.ts b/src/languages/mariadb/mariadb.keywords.ts index 58a2890a14..5bbd1719b7 100644 --- a/src/languages/mariadb/mariadb.keywords.ts +++ b/src/languages/mariadb/mariadb.keywords.ts @@ -1,259 +1,106 @@ import { flatKeywordList } from '../../utils.js'; export const keywords = flatKeywordList({ - // https://mariadb.com/kb/en/information-schema-keywords-table/ - all: [ + // https://mariadb.com/kb/en/reserved-words/ + reserved: [ 'ACCESSIBLE', - 'ACCOUNT', - 'ACTION', 'ADD', - 'ADMIN', - 'AFTER', - 'AGAINST', - 'AGGREGATE', 'ALL', - 'ALGORITHM', 'ALTER', - 'ALWAYS', 'ANALYZE', 'AND', - 'ANY', 'AS', 'ASC', - 'ASCII', 'ASENSITIVE', - 'AT', - 'ATOMIC', - 'AUTHORS', - 'AUTO_INCREMENT', - 'AUTOEXTEND_SIZE', - 'AUTO', - 'AVG', - 'AVG_ROW_LENGTH', - 'BACKUP', 'BEFORE', - 'BEGIN', 'BETWEEN', 'BIGINT', 'BINARY', - 'BINLOG', - 'BIT', 'BLOB', - 'BLOCK', - 'BODY', - 'BOOL', - 'BOOLEAN', 'BOTH', - 'BTREE', 'BY', - 'BYTE', - 'CACHE', 'CALL', 'CASCADE', - 'CASCADED', 'CASE', - 'CATALOG_NAME', - 'CHAIN', 'CHANGE', - 'CHANGED', 'CHAR', 'CHARACTER', - 'CHARSET', 'CHECK', - 'CHECKPOINT', - 'CHECKSUM', - 'CIPHER', - 'CLASS_ORIGIN', - 'CLIENT', - 'CLOB', - 'CLOSE', - 'COALESCE', - 'CODE', 'COLLATE', - 'COLLATION', 'COLUMN', - 'COLUMN_NAME', - 'COLUMNS', - 'COLUMN_ADD', - 'COLUMN_CHECK', - 'COLUMN_CREATE', - 'COLUMN_DELETE', - 'COLUMN_GET', - 'COMMENT', - 'COMMIT', - 'COMMITTED', - 'COMPACT', - 'COMPLETION', - 'COMPRESSED', - 'CONCURRENT', 'CONDITION', - 'CONNECTION', - 'CONSISTENT', 'CONSTRAINT', - 'CONSTRAINT_CATALOG', - 'CONSTRAINT_NAME', - 'CONSTRAINT_SCHEMA', - 'CONTAINS', - 'CONTEXT', 'CONTINUE', - 'CONTRIBUTORS', 'CONVERT', - 'CPU', 'CREATE', 'CROSS', - 'CUBE', - 'CURRENT', 'CURRENT_DATE', - 'CURRENT_POS', 'CURRENT_ROLE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR', - 'CURSOR_NAME', - 'CYCLE', - 'DATA', 'DATABASE', 'DATABASES', - 'DATAFILE', - 'DATE', - 'DATETIME', - 'DAY', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', - 'DEALLOCATE', 'DEC', 'DECIMAL', 'DECLARE', 'DEFAULT', - 'DEFINER', 'DELAYED', - 'DELAY_KEY_WRITE', 'DELETE', 'DELETE_DOMAIN_ID', 'DESC', 'DESCRIBE', - 'DES_KEY_FILE', 'DETERMINISTIC', - 'DIAGNOSTICS', - 'DIRECTORY', - 'DISABLE', - 'DISCARD', - 'DISK', 'DISTINCT', 'DISTINCTROW', 'DIV', - 'DO', - 'DOUBLE', 'DO_DOMAIN_IDS', + 'DOUBLE', 'DROP', 'DUAL', - 'DUMPFILE', - 'DUPLICATE', - 'DYNAMIC', 'EACH', 'ELSE', 'ELSEIF', - 'ELSIF', - 'EMPTY', - 'ENABLE', 'ENCLOSED', - 'END', - 'ENDS', - 'ENGINE', - 'ENGINES', - 'ENUM', - 'ERROR', - 'ERRORS', - 'ESCAPE', 'ESCAPED', - 'EVENT', - 'EVENTS', - 'EVERY', - 'EXAMINED', 'EXCEPT', - 'EXCHANGE', - 'EXCLUDE', - 'EXECUTE', - 'EXCEPTION', 'EXISTS', 'EXIT', - 'EXPANSION', - 'EXPIRE', - 'EXPORT', 'EXPLAIN', - 'EXTENDED', - 'EXTENT_SIZE', 'FALSE', - 'FAST', - 'FAULTS', - 'FEDERATED', 'FETCH', - 'FIELDS', - 'FILE', - 'FIRST', - 'FIXED', 'FLOAT', 'FLOAT4', 'FLOAT8', - 'FLUSH', - 'FOLLOWING', - 'FOLLOWS', 'FOR', 'FORCE', 'FOREIGN', - 'FORMAT', - 'FOUND', 'FROM', - 'FULL', 'FULLTEXT', - 'FUNCTION', 'GENERAL', - 'GENERATED', - 'GET_FORMAT', - 'GET', - 'GLOBAL', - 'GOTO', 'GRANT', - 'GRANTS', 'GROUP', - 'HANDLER', - 'HARD', - 'HASH', 'HAVING', - 'HELP', 'HIGH_PRIORITY', - 'HISTORY', - 'HOST', - 'HOSTS', - 'HOUR', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', - // 'ID', // conflicts with common column name - 'IDENTIFIED', 'IF', 'IGNORE', - 'IGNORED', 'IGNORE_DOMAIN_IDS', 'IGNORE_SERVER_IDS', - 'IMMEDIATE', - 'IMPORT', - 'INTERSECT', 'IN', - 'INCREMENT', 'INDEX', - 'INDEXES', 'INFILE', - 'INITIAL_SIZE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', - 'INSERT_METHOD', - 'INSTALL', 'INT', 'INT1', 'INT2', @@ -261,431 +108,150 @@ export const keywords = flatKeywordList({ 'INT4', 'INT8', 'INTEGER', + 'INTERSECT', 'INTERVAL', - 'INVISIBLE', 'INTO', - 'IO', - 'IO_THREAD', - 'IPC', 'IS', - 'ISOLATION', - 'ISOPEN', - 'ISSUER', 'ITERATE', - 'INVOKER', 'JOIN', - 'JSON', - 'JSON_TABLE', 'KEY', 'KEYS', - 'KEY_BLOCK_SIZE', 'KILL', - 'LANGUAGE', - 'LAST', - 'LAST_VALUE', - 'LASTVAL', 'LEADING', 'LEAVE', - 'LEAVES', 'LEFT', - 'LESS', - 'LEVEL', 'LIKE', 'LIMIT', 'LINEAR', 'LINES', - 'LIST', 'LOAD', - 'LOCAL', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', - 'LOCKED', - 'LOCKS', - 'LOGFILE', - 'LOGS', 'LONG', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', - 'MASTER', - 'MASTER_CONNECT_RETRY', - 'MASTER_DELAY', - 'MASTER_GTID_POS', - 'MASTER_HOST', - 'MASTER_LOG_FILE', - 'MASTER_LOG_POS', - 'MASTER_PASSWORD', - 'MASTER_PORT', - 'MASTER_SERVER_ID', - 'MASTER_SSL', - 'MASTER_SSL_CA', - 'MASTER_SSL_CAPATH', - 'MASTER_SSL_CERT', - 'MASTER_SSL_CIPHER', - 'MASTER_SSL_CRL', - 'MASTER_SSL_CRLPATH', - 'MASTER_SSL_KEY', - 'MASTER_SSL_VERIFY_SERVER_CERT', - 'MASTER_USER', - 'MASTER_USE_GTID', 'MASTER_HEARTBEAT_PERIOD', + 'MASTER_SSL_VERIFY_SERVER_CERT', 'MATCH', - 'MAX_CONNECTIONS_PER_HOUR', - 'MAX_QUERIES_PER_HOUR', - 'MAX_ROWS', - 'MAX_SIZE', - 'MAX_STATEMENT_TIME', - 'MAX_UPDATES_PER_HOUR', - 'MAX_USER_CONNECTIONS', 'MAXVALUE', - 'MEDIUM', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', - 'MEMORY', - 'MERGE', - 'MESSAGE_TEXT', - 'MICROSECOND', 'MIDDLEINT', - 'MIGRATE', - 'MINUS', - 'MINUTE', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', - 'MINVALUE', - 'MIN_ROWS', 'MOD', - 'MODE', 'MODIFIES', - 'MODIFY', - 'MONITOR', - 'MONTH', - 'MUTEX', - 'MYSQL', - 'MYSQL_ERRNO', - 'NAME', - 'NAMES', - 'NATIONAL', 'NATURAL', - 'NCHAR', - 'NESTED', - 'NEVER', - 'NEW', - 'NEXT', - 'NEXTVAL', - 'NO', - 'NOMAXVALUE', - 'NOMINVALUE', - 'NOCACHE', - 'NOCYCLE', - 'NO_WAIT', - 'NOWAIT', - 'NODEGROUP', - 'NONE', 'NOT', - 'NOTFOUND', 'NO_WRITE_TO_BINLOG', 'NULL', - 'NUMBER', 'NUMERIC', - 'NVARCHAR', - 'OF', 'OFFSET', - 'OLD_PASSWORD', 'ON', - 'ONE', - 'ONLINE', - 'ONLY', - 'OPEN', 'OPTIMIZE', - 'OPTIONS', 'OPTION', 'OPTIONALLY', 'OR', 'ORDER', - 'ORDINALITY', - 'OTHERS', 'OUT', 'OUTER', 'OUTFILE', 'OVER', - 'OVERLAPS', - 'OWNER', - 'PACKAGE', - 'PACK_KEYS', - 'PAGE', 'PAGE_CHECKSUM', - 'PARSER', 'PARSE_VCOL_EXPR', - 'PATH', - 'PERIOD', - 'PARTIAL', 'PARTITION', - 'PARTITIONING', - 'PARTITIONS', - 'PASSWORD', - 'PERSISTENT', - 'PHASE', - 'PLUGIN', - 'PLUGINS', - 'PORT', - 'PORTION', - 'PRECEDES', - 'PRECEDING', + 'POSITION', 'PRECISION', - 'PREPARE', - 'PRESERVE', - 'PREV', - 'PREVIOUS', 'PRIMARY', - 'PRIVILEGES', 'PROCEDURE', - 'PROCESS', - 'PROCESSLIST', - 'PROFILE', - 'PROFILES', - 'PROXY', 'PURGE', - 'QUARTER', - 'QUERY', - 'QUICK', - 'RAISE', 'RANGE', - 'RAW', 'READ', - 'READ_ONLY', - 'READ_WRITE', 'READS', + 'READ_WRITE', 'REAL', - 'REBUILD', - 'RECOVER', 'RECURSIVE', - 'REDO_BUFFER_SIZE', - 'REDOFILE', - 'REDUNDANT', + 'REF_SYSTEM_ID', 'REFERENCES', 'REGEXP', - 'RELAY', - 'RELAYLOG', - 'RELAY_LOG_FILE', - 'RELAY_LOG_POS', - 'RELAY_THREAD', 'RELEASE', - 'RELOAD', - 'REMOVE', 'RENAME', - 'REORGANIZE', - 'REPAIR', - 'REPEATABLE', - 'REPLACE', - 'REPLAY', - 'REPLICA', - 'REPLICAS', - 'REPLICA_POS', - 'REPLICATION', 'REPEAT', + 'REPLACE', 'REQUIRE', - 'RESET', 'RESIGNAL', - 'RESTART', - 'RESTORE', 'RESTRICT', - 'RESUME', - 'RETURNED_SQLSTATE', 'RETURN', 'RETURNING', - 'RETURNS', - 'REUSE', - 'REVERSE', 'REVOKE', 'RIGHT', 'RLIKE', - 'ROLE', - 'ROLLBACK', - 'ROLLUP', - 'ROUTINE', - 'ROW', - 'ROWCOUNT', - 'ROWNUM', + 'ROW_NUMBER', 'ROWS', - 'ROWTYPE', - 'ROW_COUNT', - 'ROW_FORMAT', - 'RTREE', - 'SAVEPOINT', - 'SCHEDULE', 'SCHEMA', - 'SCHEMA_NAME', 'SCHEMAS', - 'SECOND', 'SECOND_MICROSECOND', - 'SECURITY', 'SELECT', 'SENSITIVE', 'SEPARATOR', - 'SEQUENCE', - 'SERIAL', - 'SERIALIZABLE', - 'SESSION', - 'SERVER', 'SET', - 'SETVAL', - 'SHARE', 'SHOW', - 'SHUTDOWN', 'SIGNAL', - 'SIGNED', - 'SIMPLE', - 'SKIP', - 'SLAVE', - 'SLAVES', - 'SLAVE_POS', 'SLOW', - 'SNAPSHOT', 'SMALLINT', - 'SOCKET', - 'SOFT', - 'SOME', - 'SONAME', - 'SOUNDS', - 'SOURCE', - 'STAGE', - 'STORED', 'SPATIAL', 'SPECIFIC', - 'REF_SYSTEM_ID', 'SQL', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQL_BIG_RESULT', - 'SQL_BUFFER_RESULT', - 'SQL_CACHE', 'SQL_CALC_FOUND_ROWS', - 'SQL_NO_CACHE', 'SQL_SMALL_RESULT', - 'SQL_THREAD', - 'SQL_TSI_SECOND', - 'SQL_TSI_MINUTE', - 'SQL_TSI_HOUR', - 'SQL_TSI_DAY', - 'SQL_TSI_WEEK', - 'SQL_TSI_MONTH', - 'SQL_TSI_QUARTER', - 'SQL_TSI_YEAR', 'SSL', - 'START', 'STARTING', - 'STARTS', - 'STATEMENT', 'STATS_AUTO_RECALC', 'STATS_PERSISTENT', 'STATS_SAMPLE_PAGES', - 'STATUS', - 'STOP', - 'STORAGE', 'STRAIGHT_JOIN', - 'STRING', - 'SUBCLASS_ORIGIN', - 'SUBJECT', - 'SUBPARTITION', - 'SUBPARTITIONS', - 'SUPER', - 'SUSPEND', - 'SWAPS', - 'SWITCHES', - 'SYSDATE', - 'SYSTEM', - 'SYSTEM_TIME', 'TABLE', - 'TABLE_NAME', - 'TABLES', - 'TABLESPACE', - 'TABLE_CHECKSUM', - 'TEMPORARY', - 'TEMPTABLE', 'TERMINATED', - 'TEXT', - 'THAN', 'THEN', - 'TIES', - 'TIME', - 'TIMESTAMP', - 'TIMESTAMPADD', - 'TIMESTAMPDIFF', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TO', 'TRAILING', - 'TRANSACTION', - 'TRANSACTIONAL', - 'THREADS', 'TRIGGER', - 'TRIGGERS', 'TRUE', - 'TRUNCATE', - 'TYPE', - 'TYPES', - 'UNBOUNDED', - 'UNCOMMITTED', - 'UNDEFINED', - 'UNDO_BUFFER_SIZE', - 'UNDOFILE', 'UNDO', - 'UNICODE', 'UNION', 'UNIQUE', - 'UNKNOWN', 'UNLOCK', - 'UNINSTALL', 'UNSIGNED', - 'UNTIL', 'UPDATE', - 'UPGRADE', 'USAGE', 'USE', - 'USER', - 'USER_RESOURCES', - 'USE_FRM', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', - 'VALUE', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARCHARACTER', - 'VARCHAR2', - 'VARIABLES', 'VARYING', - 'VIA', - 'VIEW', - 'VIRTUAL', - 'VISIBLE', - 'VERSIONING', - 'WAIT', - 'WARNINGS', - 'WEEK', - 'WEIGHT_STRING', 'WHEN', 'WHERE', 'WHILE', 'WINDOW', 'WITH', - 'WITHIN', - 'WITHOUT', - 'WORK', - 'WRAPPER', 'WRITE', - 'X509', 'XOR', - 'XA', - 'XML', - 'YEAR', 'YEAR_MONTH', 'ZEROFILL', ], diff --git a/test/mariadb.test.ts b/test/mariadb.test.ts index d76dfdbcf2..e301ebd531 100644 --- a/test/mariadb.test.ts +++ b/test/mariadb.test.ts @@ -91,4 +91,28 @@ describe('MariaDbFormatter', () => { DROP DEFAULT; `); }); + + it('uppercases only reserved keywords', () => { + expect( + format( + `create table account (id int comment 'the most important column'); + select * from mysql.user; + insert into user (id, name) values (1, 'Blah');`, + { keywordCase: 'upper' } + ) + ).toBe(dedent` + CREATE TABLE + account (id INT comment 'the most important column'); + + SELECT + * + FROM + mysql.user; + + INSERT INTO + user (id, name) + VALUES + (1, 'Blah'); + `); + }); }); From ab2abfb06fca576a5ae2a9eaba9e897da896e204 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Fri, 1 Sep 2023 11:25:03 +0300 Subject: [PATCH 2/3] Reduce MySQL keyword list to only reserved ones --- src/languages/mysql/mysql.functions.ts | 2 +- src/languages/mysql/mysql.keywords.ts | 485 +------------------------ test/mysql.test.ts | 24 ++ 3 files changed, 26 insertions(+), 485 deletions(-) diff --git a/src/languages/mysql/mysql.functions.ts b/src/languages/mysql/mysql.functions.ts index 67ed2fbeb2..61d57521e1 100644 --- a/src/languages/mysql/mysql.functions.ts +++ b/src/languages/mysql/mysql.functions.ts @@ -402,7 +402,7 @@ export const functions = flatKeywordList({ 'UNIX_TIMESTAMP', 'UPDATEXML', 'UPPER', - 'USER', + // 'USER', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', diff --git a/src/languages/mysql/mysql.keywords.ts b/src/languages/mysql/mysql.keywords.ts index 8945e9ee0f..6658f67be7 100644 --- a/src/languages/mysql/mysql.keywords.ts +++ b/src/languages/mysql/mysql.keywords.ts @@ -2,267 +2,109 @@ import { flatKeywordList } from '../../utils.js'; export const keywords = flatKeywordList({ // https://dev.mysql.com/doc/refman/8.0/en/keywords.html - all: [ + reserved: [ 'ACCESSIBLE', // (R) - 'ACCOUNT', - 'ACTION', - 'ACTIVE', 'ADD', // (R) - 'ADMIN', - 'AFTER', - 'AGAINST', - 'AGGREGATE', - 'ALGORITHM', 'ALL', // (R) 'ALTER', // (R) - 'ALWAYS', 'ANALYZE', // (R) 'AND', // (R) - 'ANY', - 'ARRAY', 'AS', // (R) 'ASC', // (R) - 'ASCII', 'ASENSITIVE', // (R) - 'AT', - 'ATTRIBUTE', - 'AUTHENTICATION', - 'AUTOEXTEND_SIZE', - 'AUTO_INCREMENT', - 'AVG', - 'AVG_ROW_LENGTH', - 'BACKUP', 'BEFORE', // (R) - 'BEGIN', 'BETWEEN', // (R) 'BIGINT', // (R) 'BINARY', // (R) - 'BINLOG', - 'BIT', 'BLOB', // (R) - 'BLOCK', - 'BOOL', - 'BOOLEAN', 'BOTH', // (R) - 'BTREE', - 'BUCKETS', 'BY', // (R) - 'BYTE', - 'CACHE', 'CALL', // (R) 'CASCADE', // (R) - 'CASCADED', 'CASE', // (R) - 'CATALOG_NAME', - 'CHAIN', - 'CHALLENGE_RESPONSE', 'CHANGE', // (R) - 'CHANGED', - 'CHANNEL', 'CHAR', // (R) 'CHARACTER', // (R) - 'CHARSET', 'CHECK', // (R) - 'CHECKSUM', - 'CIPHER', - 'CLASS_ORIGIN', - 'CLIENT', - 'CLONE', - 'CLOSE', - 'COALESCE', - 'CODE', 'COLLATE', // (R) - 'COLLATION', 'COLUMN', // (R) - 'COLUMNS', - 'COLUMN_FORMAT', - 'COLUMN_NAME', - 'COMMENT', - 'COMMIT', - 'COMMITTED', - 'COMPACT', - 'COMPLETION', - 'COMPONENT', - 'COMPRESSED', - 'COMPRESSION', - 'CONCURRENT', 'CONDITION', // (R) - 'CONNECTION', - 'CONSISTENT', 'CONSTRAINT', // (R) - 'CONSTRAINT_CATALOG', - 'CONSTRAINT_NAME', - 'CONSTRAINT_SCHEMA', - 'CONTAINS', - 'CONTEXT', 'CONTINUE', // (R) 'CONVERT', // (R) - 'CPU', 'CREATE', // (R) 'CROSS', // (R) 'CUBE', // (R) 'CUME_DIST', // (R) - 'CURRENT', 'CURRENT_DATE', // (R) 'CURRENT_TIME', // (R) 'CURRENT_TIMESTAMP', // (R) 'CURRENT_USER', // (R) 'CURSOR', // (R) - 'CURSOR_NAME', - 'DATA', 'DATABASE', // (R) 'DATABASES', // (R) - 'DATAFILE', - 'DATE', - 'DATETIME', - 'DAY', 'DAY_HOUR', // (R) 'DAY_MICROSECOND', // (R) 'DAY_MINUTE', // (R) 'DAY_SECOND', // (R) - 'DEALLOCATE', 'DEC', // (R) 'DECIMAL', // (R) 'DECLARE', // (R) 'DEFAULT', // (R) - 'DEFAULT_AUTH', - 'DEFINER', - 'DEFINITION', 'DELAYED', // (R) - 'DELAY_KEY_WRITE', 'DELETE', // (R) 'DENSE_RANK', // (R) 'DESC', // (R) 'DESCRIBE', // (R) - 'DESCRIPTION', 'DETERMINISTIC', // (R) - 'DIAGNOSTICS', - 'DIRECTORY', - 'DISABLE', - 'DISCARD', - 'DISK', 'DISTINCT', // (R) 'DISTINCTROW', // (R) 'DIV', // (R) - 'DO', 'DOUBLE', // (R) 'DROP', // (R) 'DUAL', // (R) - 'DUMPFILE', - 'DUPLICATE', - 'DYNAMIC', 'EACH', // (R) 'ELSE', // (R) 'ELSEIF', // (R) 'EMPTY', // (R) - 'ENABLE', 'ENCLOSED', // (R) - 'ENCRYPTION', - 'END', - 'ENDS', - 'ENFORCED', - 'ENGINE', - 'ENGINES', - 'ENGINE_ATTRIBUTE', - 'ENUM', - 'ERROR', - 'ERRORS', - 'ESCAPE', 'ESCAPED', // (R) - 'EVENT', - 'EVENTS', - 'EVERY', 'EXCEPT', // (R) - 'EXCHANGE', - 'EXCLUDE', - 'EXECUTE', 'EXISTS', // (R) 'EXIT', // (R) - 'EXPANSION', - 'EXPIRE', 'EXPLAIN', // (R) - 'EXPORT', - 'EXTENDED', - 'EXTENT_SIZE', - 'FACTOR', - 'FAILED_LOGIN_ATTEMPTS', 'FALSE', // (R) - 'FAST', - 'FAULTS', 'FETCH', // (R) - 'FIELDS', - 'FILE', - 'FILE_BLOCK_SIZE', - 'FILTER', - 'FINISH', - 'FIRST', 'FIRST_VALUE', // (R) - 'FIXED', 'FLOAT', // (R) 'FLOAT4', // (R) 'FLOAT8', // (R) - 'FLUSH', - 'FOLLOWING', - 'FOLLOWS', 'FOR', // (R) 'FORCE', // (R) 'FOREIGN', // (R) - 'FORMAT', - 'FOUND', 'FROM', // (R) - 'FULL', 'FULLTEXT', // (R) 'FUNCTION', // (R) - 'GENERAL', 'GENERATED', // (R) - 'GEOMCOLLECTION', - 'GEOMETRY', - 'GEOMETRYCOLLECTION', 'GET', // (R) - 'GET_FORMAT', - 'GET_MASTER_PUBLIC_KEY', - 'GET_SOURCE_PUBLIC_KEY', - 'GLOBAL', 'GRANT', // (R) - 'GRANTS', 'GROUP', // (R) 'GROUPING', // (R) 'GROUPS', // (R) - 'GROUP_REPLICATION', - 'GTID_ONLY', - 'HANDLER', - 'HASH', 'HAVING', // (R) - 'HELP', 'HIGH_PRIORITY', // (R) - 'HISTOGRAM', - 'HISTORY', - 'HOST', - 'HOSTS', - 'HOUR', 'HOUR_MICROSECOND', // (R) 'HOUR_MINUTE', // (R) 'HOUR_SECOND', // (R) - 'IDENTIFIED', 'IF', // (R) 'IGNORE', // (R) - 'IGNORE_SERVER_IDS', - 'IMPORT', 'IN', // (R) - 'INACTIVE', 'INDEX', // (R) - 'INDEXES', 'INFILE', // (R) - 'INITIAL', - 'INITIAL_SIZE', - 'INITIATE', 'INNER', // (R) 'INOUT', // (R) 'INSENSITIVE', // (R) 'INSERT', // (R) - 'INSERT_METHOD', - 'INSTALL', - 'INSTANCE', 'IN', // <-- moved over from functions 'INT', // (R) 'INT1', // (R) @@ -274,480 +116,155 @@ export const keywords = flatKeywordList({ 'INTERSECT', // (R) 'INTERVAL', // (R) 'INTO', // (R) - 'INVISIBLE', - 'INVOKER', - 'IO', 'IO_AFTER_GTIDS', // (R) 'IO_BEFORE_GTIDS', // (R) - 'IO_THREAD', - 'IPC', 'IS', // (R) - 'ISOLATION', - 'ISSUER', 'ITERATE', // (R) 'JOIN', // (R) - 'JSON', 'JSON_TABLE', // (R) - 'JSON_VALUE', 'KEY', // (R) - 'KEYRING', 'KEYS', // (R) - 'KEY_BLOCK_SIZE', 'KILL', // (R) 'LAG', // (R) - 'LANGUAGE', - 'LAST', 'LAST_VALUE', // (R) 'LATERAL', // (R) 'LEAD', // (R) 'LEADING', // (R) 'LEAVE', // (R) - 'LEAVES', 'LEFT', // (R) - 'LESS', - 'LEVEL', 'LIKE', // (R) 'LIMIT', // (R) 'LINEAR', // (R) 'LINES', // (R) - 'LINESTRING', - 'LIST', 'LOAD', // (R) - 'LOCAL', 'LOCALTIME', // (R) 'LOCALTIMESTAMP', // (R) 'LOCK', // (R) - 'LOCKED', - 'LOCKS', - 'LOGFILE', - 'LOGS', 'LONG', // (R) 'LONGBLOB', // (R) 'LONGTEXT', // (R) 'LOOP', // (R) 'LOW_PRIORITY', // (R) - 'MASTER', - 'MASTER_AUTO_POSITION', 'MASTER_BIND', // (R) - 'MASTER_COMPRESSION_ALGORITHMS', - 'MASTER_CONNECT_RETRY', - 'MASTER_DELAY', - 'MASTER_HEARTBEAT_PERIOD', - 'MASTER_HOST', - 'MASTER_LOG_FILE', - 'MASTER_LOG_POS', - 'MASTER_PASSWORD', - 'MASTER_PORT', - 'MASTER_PUBLIC_KEY_PATH', - 'MASTER_RETRY_COUNT', - 'MASTER_SSL', - 'MASTER_SSL_CA', - 'MASTER_SSL_CAPATH', - 'MASTER_SSL_CERT', - 'MASTER_SSL_CIPHER', - 'MASTER_SSL_CRL', - 'MASTER_SSL_CRLPATH', - 'MASTER_SSL_KEY', 'MASTER_SSL_VERIFY_SERVER_CERT', // (R) - 'MASTER_TLS_CIPHERSUITES', - 'MASTER_TLS_VERSION', - 'MASTER_USER', - 'MASTER_ZSTD_COMPRESSION_LEVEL', 'MATCH', // (R) 'MAXVALUE', // (R) - 'MAX_CONNECTIONS_PER_HOUR', - 'MAX_QUERIES_PER_HOUR', - 'MAX_ROWS', - 'MAX_SIZE', - 'MAX_UPDATES_PER_HOUR', - 'MAX_USER_CONNECTIONS', - 'MEDIUM', 'MEDIUMBLOB', // (R) 'MEDIUMINT', // (R) 'MEDIUMTEXT', // (R) - 'MEMBER', - 'MEMORY', - 'MERGE', - 'MESSAGE_TEXT', - 'MICROSECOND', 'MIDDLEINT', // (R) - 'MIGRATE', - 'MINUTE', 'MINUTE_MICROSECOND', // (R) 'MINUTE_SECOND', // (R) - 'MIN_ROWS', 'MOD', // (R) - 'MODE', 'MODIFIES', // (R) - 'MODIFY', - 'MONTH', - 'MULTILINESTRING', - 'MULTIPOINT', - 'MULTIPOLYGON', - 'MUTEX', - 'MYSQL_ERRNO', - 'NAME', - 'NAMES', - 'NATIONAL', 'NATURAL', // (R) - 'NCHAR', - 'NDB', - 'NDBCLUSTER', - 'NESTED', - 'NETWORK_NAMESPACE', - 'NEVER', - 'NEW', - 'NEXT', - 'NO', - 'NODEGROUP', - 'NONE', 'NOT', // (R) - 'NOWAIT', - 'NO_WAIT', 'NO_WRITE_TO_BINLOG', // (R) 'NTH_VALUE', // (R) 'NTILE', // (R) 'NULL', // (R) - 'NULLS', - 'NUMBER', 'NUMERIC', // (R) - 'NVARCHAR', 'OF', // (R) - 'OFF', - 'OFFSET', - 'OJ', - 'OLD', 'ON', // (R) - 'ONE', - 'ONLY', - 'OPEN', 'OPTIMIZE', // (R) 'OPTIMIZER_COSTS', // (R) 'OPTION', // (R) - 'OPTIONAL', 'OPTIONALLY', // (R) - 'OPTIONS', 'OR', // (R) 'ORDER', // (R) - 'ORDINALITY', - 'ORGANIZATION', - 'OTHERS', 'OUT', // (R) 'OUTER', // (R) 'OUTFILE', // (R) 'OVER', // (R) - 'OWNER', - 'PACK_KEYS', - 'PAGE', - 'PARSER', - 'PARTIAL', 'PARTITION', // (R) - 'PARTITIONING', - 'PARTITIONS', - 'PASSWORD', - 'PASSWORD_LOCK_TIME', - 'PATH', 'PERCENT_RANK', // (R) - 'PERSIST', - 'PERSIST_ONLY', - 'PHASE', - 'PLUGIN', - 'PLUGINS', - 'PLUGIN_DIR', - 'POINT', - 'POLYGON', - 'PORT', - 'PRECEDES', - 'PRECEDING', 'PRECISION', // (R) - 'PREPARE', - 'PRESERVE', - 'PREV', 'PRIMARY', // (R) - 'PRIVILEGES', - 'PRIVILEGE_CHECKS_USER', 'PROCEDURE', // (R) - 'PROCESS', - 'PROCESSLIST', - 'PROFILE', - 'PROFILES', - 'PROXY', 'PURGE', // (R) - 'QUARTER', - 'QUERY', - 'QUICK', - 'RANDOM', 'RANGE', // (R) 'RANK', // (R) 'READ', // (R) 'READS', // (R) - 'READ_ONLY', 'READ_WRITE', // (R) 'REAL', // (R) - 'REBUILD', - 'RECOVER', 'RECURSIVE', // (R) - 'REDO_BUFFER_SIZE', - 'REDUNDANT', - 'REFERENCE', 'REFERENCES', // (R) 'REGEXP', // (R) - 'REGISTRATION', - 'RELAY', - 'RELAYLOG', - 'RELAY_LOG_FILE', - 'RELAY_LOG_POS', - 'RELAY_THREAD', 'RELEASE', // (R) - 'RELOAD', - 'REMOVE', 'RENAME', // (R) - 'REORGANIZE', - 'REPAIR', 'REPEAT', // (R) - 'REPEATABLE', 'REPLACE', // (R) - 'REPLICA', - 'REPLICAS', - 'REPLICATE_DO_DB', - 'REPLICATE_DO_TABLE', - 'REPLICATE_IGNORE_DB', - 'REPLICATE_IGNORE_TABLE', - 'REPLICATE_REWRITE_DB', - 'REPLICATE_WILD_DO_TABLE', - 'REPLICATE_WILD_IGNORE_TABLE', - 'REPLICATION', 'REQUIRE', // (R) - 'REQUIRE_ROW_FORMAT', - 'RESET', 'RESIGNAL', // (R) - 'RESOURCE', - 'RESPECT', - 'RESTART', - 'RESTORE', 'RESTRICT', // (R) - 'RESUME', - 'RETAIN', 'RETURN', // (R) - 'RETURNED_SQLSTATE', - 'RETURNING', - 'RETURNS', - 'REUSE', - 'REVERSE', 'REVOKE', // (R) 'RIGHT', // (R) 'RLIKE', // (R) - 'ROLE', - 'ROLLBACK', - 'ROLLUP', - 'ROTATE', - 'ROUTINE', 'ROW', // (R) 'ROWS', // (R) - 'ROW_COUNT', - 'ROW_FORMAT', 'ROW_NUMBER', // (R) - 'RTREE', - 'SAVEPOINT', - 'SCHEDULE', 'SCHEMA', // (R) 'SCHEMAS', // (R) - 'SCHEMA_NAME', - 'SECOND', - 'SECONDARY', - 'SECONDARY_ENGINE', - 'SECONDARY_ENGINE_ATTRIBUTE', - 'SECONDARY_LOAD', - 'SECONDARY_UNLOAD', 'SECOND_MICROSECOND', // (R) - 'SECURITY', 'SELECT', // (R) 'SENSITIVE', // (R) 'SEPARATOR', // (R) - 'SERIAL', - 'SERIALIZABLE', - 'SERVER', - 'SESSION', 'SET', // (R) - 'SHARE', 'SHOW', // (R) - 'SHUTDOWN', 'SIGNAL', // (R) - 'SIGNED', - 'SIMPLE', - 'SKIP', - 'SLAVE', - 'SLOW', 'SMALLINT', // (R) - 'SNAPSHOT', - 'SOCKET', - 'SOME', - 'SONAME', - 'SOUNDS', - 'SOURCE', - 'SOURCE_AUTO_POSITION', - 'SOURCE_BIND', - 'SOURCE_COMPRESSION_ALGORITHMS', - 'SOURCE_CONNECT_RETRY', - 'SOURCE_DELAY', - 'SOURCE_HEARTBEAT_PERIOD', - 'SOURCE_HOST', - 'SOURCE_LOG_FILE', - 'SOURCE_LOG_POS', - 'SOURCE_PASSWORD', - 'SOURCE_PORT', - 'SOURCE_PUBLIC_KEY_PATH', - 'SOURCE_RETRY_COUNT', - 'SOURCE_SSL', - 'SOURCE_SSL_CA', - 'SOURCE_SSL_CAPATH', - 'SOURCE_SSL_CERT', - 'SOURCE_SSL_CIPHER', - 'SOURCE_SSL_CRL', - 'SOURCE_SSL_CRLPATH', - 'SOURCE_SSL_KEY', - 'SOURCE_SSL_VERIFY_SERVER_CERT', - 'SOURCE_TLS_CIPHERSUITES', - 'SOURCE_TLS_VERSION', - 'SOURCE_USER', - 'SOURCE_ZSTD_COMPRESSION_LEVEL', 'SPATIAL', // (R) 'SPECIFIC', // (R) 'SQL', // (R) 'SQLEXCEPTION', // (R) 'SQLSTATE', // (R) 'SQLWARNING', // (R) - 'SQL_AFTER_GTIDS', - 'SQL_AFTER_MTS_GAPS', - 'SQL_BEFORE_GTIDS', 'SQL_BIG_RESULT', // (R) - 'SQL_BUFFER_RESULT', 'SQL_CALC_FOUND_ROWS', // (R) - 'SQL_NO_CACHE', 'SQL_SMALL_RESULT', // (R) - 'SQL_THREAD', - 'SQL_TSI_DAY', - 'SQL_TSI_HOUR', - 'SQL_TSI_MINUTE', - 'SQL_TSI_MONTH', - 'SQL_TSI_QUARTER', - 'SQL_TSI_SECOND', - 'SQL_TSI_WEEK', - 'SQL_TSI_YEAR', - 'SRID', 'SSL', // (R) - 'STACKED', - 'START', 'STARTING', // (R) - 'STARTS', - 'STATS_AUTO_RECALC', - 'STATS_PERSISTENT', - 'STATS_SAMPLE_PAGES', - 'STATUS', - 'STOP', - 'STORAGE', 'STORED', // (R) 'STRAIGHT_JOIN', // (R) - 'STREAM', - 'STRING', - 'SUBCLASS_ORIGIN', - 'SUBJECT', - 'SUBPARTITION', - 'SUBPARTITIONS', - 'SUPER', - 'SUSPEND', - 'SWAPS', - 'SWITCHES', 'SYSTEM', // (R) 'TABLE', // (R) - 'TABLES', - 'TABLESPACE', - 'TABLE_CHECKSUM', - 'TABLE_NAME', - 'TEMPORARY', - 'TEMPTABLE', 'TERMINATED', // (R) - 'TEXT', - 'THAN', 'THEN', // (R) - 'THREAD_PRIORITY', - 'TIES', - 'TIME', - 'TIMESTAMP', - 'TIMESTAMPADD', - 'TIMESTAMPDIFF', 'TINYBLOB', // (R) 'TINYINT', // (R) 'TINYTEXT', // (R) - 'TLS', 'TO', // (R) 'TRAILING', // (R) - 'TRANSACTION', 'TRIGGER', // (R) - 'TRIGGERS', 'TRUE', // (R) - 'TRUNCATE', - 'TYPE', - 'TYPES', - 'UNBOUNDED', - 'UNCOMMITTED', - 'UNDEFINED', 'UNDO', // (R) - 'UNDOFILE', - 'UNDO_BUFFER_SIZE', - 'UNICODE', - 'UNINSTALL', 'UNION', // (R) 'UNIQUE', // (R) - 'UNKNOWN', 'UNLOCK', // (R) - 'UNREGISTER', 'UNSIGNED', // (R) - 'UNTIL', 'UPDATE', // (R) - 'UPGRADE', 'USAGE', // (R) 'USE', // (R) - 'USER', - 'USER_RESOURCES', - 'USE_FRM', 'USING', // (R) 'UTC_DATE', // (R) 'UTC_TIME', // (R) 'UTC_TIMESTAMP', // (R) - 'VALIDATION', - 'VALUE', 'VALUES', // (R) 'VARBINARY', // (R) 'VARCHAR', // (R) 'VARCHARACTER', // (R) - 'VARIABLES', 'VARYING', // (R) - 'VCPU', - 'VIEW', 'VIRTUAL', // (R) - 'VISIBLE', - 'WAIT', - 'WARNINGS', - 'WEEK', - 'WEIGHT_STRING', 'WHEN', // (R) 'WHERE', // (R) 'WHILE', // (R) 'WINDOW', // (R) 'WITH', // (R) - 'WITHOUT', - 'WORK', - 'WRAPPER', 'WRITE', // (R) - 'X509', - 'XA', - 'XID', - 'XML', 'XOR', // (R) - 'YEAR', 'YEAR_MONTH', // (R) 'ZEROFILL', // (R) - 'ZONE', ], }); diff --git a/test/mysql.test.ts b/test/mysql.test.ts index 405476f83c..eb7a7e364f 100644 --- a/test/mysql.test.ts +++ b/test/mysql.test.ts @@ -93,4 +93,28 @@ describe('MySqlFormatter', () => { DROP DEFAULT; `); }); + + it('uppercases only reserved keywords', () => { + expect( + format( + `create table account (id int comment 'the most important column'); + select * from mysql.user; + insert into user (id, name) values (1, 'Blah');`, + { keywordCase: 'upper' } + ) + ).toBe(dedent` + CREATE TABLE + account (id INT comment 'the most important column'); + + SELECT + * + FROM + mysql.user; + + INSERT INTO + user (id, name) + VALUES + (1, 'Blah'); + `); + }); }); From 0445c9b16a696ee02a415d0ce44b2215218eab74 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Fri, 1 Sep 2023 12:38:40 +0300 Subject: [PATCH 3/3] Reduce SingleStoreDB keyword list to only reserved ones --- .../singlestoredb/singlestoredb.functions.ts | 2 +- .../singlestoredb/singlestoredb.keywords.ts | 605 +----------------- test/singlestoredb.test.ts | 24 + 3 files changed, 30 insertions(+), 601 deletions(-) diff --git a/src/languages/singlestoredb/singlestoredb.functions.ts b/src/languages/singlestoredb/singlestoredb.functions.ts index a064b98bca..3c7b92b0a5 100644 --- a/src/languages/singlestoredb/singlestoredb.functions.ts +++ b/src/languages/singlestoredb/singlestoredb.functions.ts @@ -266,7 +266,7 @@ export const functions = flatKeywordList({ 'UNIX_TIMESTAMP', 'UPDATEXML', 'UPPER', - 'USER', + // 'USER', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', diff --git a/src/languages/singlestoredb/singlestoredb.keywords.ts b/src/languages/singlestoredb/singlestoredb.keywords.ts index 5e4cfe7279..c09d475b94 100644 --- a/src/languages/singlestoredb/singlestoredb.keywords.ts +++ b/src/languages/singlestoredb/singlestoredb.keywords.ts @@ -1,366 +1,109 @@ import { flatKeywordList } from '../../utils.js'; export const keywords = flatKeywordList({ - // https://docs.singlestore.com/managed-service/en/reference/sql-reference.html + // List of all keywords taken from: // https://docs.singlestore.com/managed-service/en/reference/sql-reference/restricted-keywords/list-of-restricted-keywords.html - all: [ - 'ABORT', - 'ABSOLUTE', - 'ACCESS', - 'ACCESSIBLE', - 'ACCOUNT', - 'ACTION', - 'ACTIVE', + // Then filtered down to reserved keywords by running + // > SELECT * AS ; + // for each keyword in that list and observing which of these produce an error. + reserved: [ 'ADD', - 'ADMIN', - 'AFTER', - 'AGAINST', - 'AGGREGATE', - 'AGGREGATES', - 'AGGREGATOR', - 'AGGREGATOR_ID', - 'AGGREGATOR_PLAN_HASH', - 'AGGREGATORS', - 'ALGORITHM', 'ALL', - 'ALSO', 'ALTER', - 'ALWAYS', 'ANALYZE', 'AND', - 'ANY', - 'ARGHISTORY', - 'ARRANGE', - 'ARRANGEMENT', - 'ARRAY', 'AS', 'ASC', - 'ASCII', 'ASENSITIVE', - 'ASM', - 'ASSERTION', - 'ASSIGNMENT', - 'AST', - 'ASYMMETRIC', - 'ASYNC', - 'AT', - 'ATTACH', - 'ATTRIBUTE', - 'AUTHORIZATION', - 'AUTO', - 'AUTO_INCREMENT', - 'AUTO_REPROVISION', - 'AUTOSTATS', - 'AUTOSTATS_CARDINALITY_MODE', - 'AUTOSTATS_ENABLED', - 'AUTOSTATS_HISTOGRAM_MODE', - 'AUTOSTATS_SAMPLING', - 'AVAILABILITY', - 'AVG', - 'AVG_ROW_LENGTH', - 'AVRO', - 'AZURE', - 'BACKGROUND', - '_BACKGROUND_THREADS_FOR_CLEANUP', - 'BACKUP', - 'BACKUP_HISTORY', - 'BACKUP_ID', - 'BACKWARD', - 'BATCH', - 'BATCHES', - 'BATCH_INTERVAL', - '_BATCH_SIZE_LIMIT', 'BEFORE', - 'BEGIN', 'BETWEEN', 'BIGINT', 'BINARY', '_BINARY', - 'BIT', 'BLOB', - 'BOOL', - 'BOOLEAN', - 'BOOTSTRAP', 'BOTH', - '_BT', - 'BTREE', - 'BUCKET_COUNT', - 'BUCKETS', 'BY', - 'BYTE', - 'BYTE_LENGTH', - 'CACHE', 'CALL', - 'CALL_FOR_PIPELINE', - 'CALLED', - 'CAPTURE', 'CASCADE', - 'CASCADED', 'CASE', - 'CATALOG', - 'CHAIN', 'CHANGE', 'CHAR', 'CHARACTER', - 'CHARACTERISTICS', - 'CHARSET', 'CHECK', - 'CHECKPOINT', - '_CHECK_CAN_CONNECT', - '_CHECK_CONSISTENCY', - 'CHECKSUM', - '_CHECKSUM', - 'CLASS', - 'CLEAR', - 'CLIENT', - 'CLIENT_FOUND_ROWS', - 'CLOSE', - 'CLUSTER', - 'CLUSTERED', - 'CNF', - 'COALESCE', 'COLLATE', - 'COLLATION', 'COLUMN', - 'COLUMNAR', - 'COLUMNS', - 'COLUMNSTORE', - 'COLUMNSTORE_SEGMENT_ROWS', - 'COMMENT', - 'COMMENTS', - 'COMMIT', - 'COMMITTED', - '_COMMIT_LOG_TAIL', - 'COMPACT', - 'COMPILE', - 'COMPRESSED', - 'COMPRESSION', - 'CONCURRENT', - 'CONCURRENTLY', 'CONDITION', - 'CONFIGURATION', - 'CONNECTION', - 'CONNECTIONS', - 'CONFIG', 'CONSTRAINT', - 'CONTAINS', - 'CONTENT', 'CONTINUE', - '_CONTINUE_REPLAY', - 'CONVERSION', 'CONVERT', - 'COPY', - '_CORE', - 'COST', 'CREATE', - 'CREDENTIALS', 'CROSS', - 'CUBE', - 'CSV', - 'CUME_DIST', - 'CURRENT', - 'CURRENT_CATALOG', 'CURRENT_DATE', - 'CURRENT_SCHEMA', - 'CURRENT_SECURITY_GROUPS', - 'CURRENT_SECURITY_ROLES', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR', - 'CYCLE', - 'DATA', 'DATABASE', 'DATABASES', - 'DATE', - 'DATETIME', - 'DAY', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', - 'DEALLOCATE', 'DEC', 'DECIMAL', 'DECLARE', 'DEFAULT', - 'DEFAULTS', - 'DEFERRABLE', - 'DEFERRED', - 'DEFINED', - 'DEFINER', 'DELAYED', - 'DELAY_KEY_WRITE', 'DELETE', - 'DELIMITER', - 'DELIMITERS', - 'DENSE_RANK', 'DESC', 'DESCRIBE', - 'DETACH', 'DETERMINISTIC', - 'DICTIONARY', - 'DIFFERENTIAL', - 'DIRECTORY', - 'DISABLE', - 'DISCARD', - '_DISCONNECT', - 'DISK', 'DISTINCT', 'DISTINCTROW', - 'DISTRIBUTED_JOINS', 'DIV', - 'DO', - 'DOCUMENT', - 'DOMAIN', 'DOUBLE', 'DROP', - '_DROP_PROFILE', 'DUAL', - 'DUMP', - 'DUPLICATE', - 'DURABILITY', - 'DYNAMIC', - 'EARLIEST', 'EACH', - 'ECHO', - 'ELECTION', 'ELSE', 'ELSEIF', - 'ENABLE', 'ENCLOSED', - 'ENCODING', - 'ENCRYPTED', - 'END', - 'ENGINE', - 'ENGINES', - 'ENUM', - 'ERRORS', - 'ESCAPE', 'ESCAPED', - 'ESTIMATE', - 'EVENT', - 'EVENTS', 'EXCEPT', - 'EXCLUDE', - 'EXCLUDING', - 'EXCLUSIVE', - 'EXECUTE', 'EXISTS', 'EXIT', 'EXPLAIN', - 'EXTENDED', - 'EXTENSION', - 'EXTERNAL', - 'EXTERNAL_HOST', - 'EXTERNAL_PORT', - 'EXTRACTOR', - 'EXTRACTORS', 'EXTRA_JOIN', - '_FAILOVER', - 'FAILED_LOGIN_ATTEMPTS', - 'FAILURE', 'FALSE', - 'FAMILY', - 'FAULT', 'FETCH', - 'FIELDS', - 'FILE', - 'FILES', - 'FILL', - 'FIX_ALTER', - 'FIXED', 'FLOAT', 'FLOAT4', 'FLOAT8', - 'FLUSH', - 'FOLLOWING', 'FOR', 'FORCE', 'FORCE_COMPILED_MODE', 'FORCE_INTERPRETER_MODE', - 'FOREGROUND', 'FOREIGN', - 'FORMAT', - 'FORWARD', - 'FREEZE', 'FROM', - 'FS', - '_FSYNC', 'FULL', 'FULLTEXT', - 'FUNCTION', - 'FUNCTIONS', - 'GC', - 'GCS', - 'GET_FORMAT', - '_GC', - '_GCX', - 'GENERATE', - 'GEOGRAPHY', - 'GEOGRAPHYPOINT', - 'GEOMETRY', - 'GEOMETRYPOINT', - 'GLOBAL', - '_GLOBAL_VERSION_TIMESTAMP', 'GRANT', - 'GRANTED', - 'GRANTS', 'GROUP', - 'GROUPING', - 'GROUPS', - 'GZIP', - 'HANDLE', - 'HANDLER', - 'HARD_CPU_LIMIT_PERCENTAGE', - 'HASH', - 'HAS_TEMP_TABLES', 'HAVING', - 'HDFS', - 'HEADER', 'HEARTBEAT_NO_LOGGING', 'HIGH_PRIORITY', - 'HISTOGRAM', - 'HOLD', - 'HOLDING', - 'HOST', - 'HOSTS', - 'HOUR', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', - 'IDENTIFIED', - 'IDENTITY', 'IF', 'IGNORE', - 'ILIKE', - 'IMMEDIATE', - 'IMMUTABLE', - 'IMPLICIT', - 'IMPORT', 'IN', - 'INCLUDING', - 'INCREMENT', - 'INCREMENTAL', 'INDEX', - 'INDEXES', 'INFILE', - 'INHERIT', - 'INHERITS', - '_INIT_PROFILE', - 'INIT', - 'INITIALIZE', - 'INITIALLY', - 'INJECT', - 'INLINE', 'INNER', 'INOUT', - 'INPUT', 'INSENSITIVE', 'INSERT', - 'INSERT_METHOD', - 'INSTANCE', - 'INSTEAD', 'IN', 'INT', 'INT1', @@ -370,335 +113,92 @@ export const keywords = flatKeywordList({ 'INT8', 'INTEGER', '_INTERNAL_DYNAMIC_TYPECAST', - 'INTERPRETER_MODE', 'INTERSECT', 'INTERVAL', 'INTO', - 'INVOKER', - 'ISOLATION', 'ITERATE', 'JOIN', - 'JSON', - 'KAFKA', 'KEY', - 'KEY_BLOCK_SIZE', 'KEYS', 'KILL', - 'KILLALL', - 'LABEL', - 'LAG', - 'LANGUAGE', - 'LARGE', - 'LAST', - 'LAST_VALUE', - 'LATERAL', - 'LATEST', - 'LC_COLLATE', - 'LC_CTYPE', - 'LEAD', 'LEADING', - 'LEAF', - 'LEAKPROOF', 'LEAVE', - 'LEAVES', 'LEFT', - 'LEVEL', - 'LICENSE', 'LIKE', 'LIMIT', 'LINES', - 'LISTEN', - 'LLVM', - 'LOADDATA_WHERE', 'LOAD', - 'LOCAL', 'LOCALTIME', 'LOCALTIMESTAMP', - 'LOCATION', 'LOCK', 'LONG', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', - '_LS', - 'LZ4', - 'MANAGEMENT', - '_MANAGEMENT_THREAD', - 'MAPPING', - 'MASTER', 'MATCH', - 'MATERIALIZED', 'MAXVALUE', - 'MAX_CONCURRENCY', - 'MAX_ERRORS', - 'MAX_PARTITIONS_PER_BATCH', - 'MAX_QUEUE_DEPTH', - 'MAX_RETRIES_PER_BATCH_PARTITION', - 'MAX_ROWS', - 'MBC', - 'MPL', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', - 'MEMBER', - 'MEMORY', - 'MEMORY_PERCENTAGE', - '_MEMSQL_TABLE_ID_LOOKUP', - 'MEMSQL', - 'MEMSQL_DESERIALIZE', - 'MEMSQL_IMITATING_KAFKA', - 'MEMSQL_SERIALIZE', - 'MERGE', - 'METADATA', - 'MICROSECOND', 'MIDDLEINT', - 'MIN_ROWS', 'MINUS', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', - 'MINVALUE', 'MOD', - 'MODE', - 'MODEL', 'MODIFIES', - 'MODIFY', - 'MONTH', - 'MOVE', - 'MPL', - 'NAMES', - 'NAMED', - 'NAMESPACE', - 'NATIONAL', 'NATURAL', - 'NCHAR', - 'NEXT', - 'NO', - 'NODE', - 'NONE', 'NO_QUERY_REWRITE', - 'NOPARAM', 'NOT', - 'NOTHING', - 'NOTIFY', - 'NOWAIT', 'NO_WRITE_TO_BINLOG', 'NO_QUERY_REWRITE', - 'NORELY', - 'NTH_VALUE', - 'NTILE', 'NULL', - 'NULLCOLS', - 'NULLS', 'NUMERIC', - 'NVARCHAR', - 'OBJECT', - 'OF', - 'OFF', - 'OFFLINE', - 'OFFSET', - 'OFFSETS', - 'OIDS', 'ON', - 'ONLINE', - 'ONLY', - 'OPEN', - 'OPERATOR', - 'OPTIMIZATION', 'OPTIMIZE', - 'OPTIMIZER', - 'OPTIMIZER_STATE', 'OPTION', - 'OPTIONS', 'OPTIONALLY', 'OR', 'ORDER', - 'ORDERED_SERIALIZE', - 'ORPHAN', 'OUT', - 'OUT_OF_ORDER', 'OUTER', 'OUTFILE', 'OVER', - 'OVERLAPS', - 'OVERLAY', - 'OWNED', - 'OWNER', - 'PACK_KEYS', - 'PAIRED', - 'PARSER', - 'PARQUET', - 'PARTIAL', - 'PARTITION', - 'PARTITION_ID', - 'PARTITIONING', - 'PARTITIONS', - 'PASSING', - 'PASSWORD', - 'PASSWORD_LOCK_TIME', - 'PAUSE', - '_PAUSE_REPLAY', - 'PERIODIC', - 'PERSISTED', - 'PIPELINE', - 'PIPELINES', - 'PLACING', - 'PLAN', - 'PLANS', - 'PLANCACHE', - 'PLUGINS', - 'POOL', - 'POOLS', - 'PORT', - 'PRECEDING', 'PRECISION', - 'PREPARE', - 'PRESERVE', 'PRIMARY', - 'PRIOR', - 'PRIVILEGES', - 'PROCEDURAL', 'PROCEDURE', - 'PROCEDURES', - 'PROCESS', - 'PROCESSLIST', - 'PROFILE', - 'PROFILES', - 'PROGRAM', - 'PROMOTE', - 'PROXY', 'PURGE', - 'QUARTER', - 'QUERIES', - 'QUERY', - 'QUERY_TIMEOUT', - 'QUEUE', 'RANGE', - 'RANK', 'READ', - '_READ', 'READS', 'REAL', - 'REASSIGN', - 'REBALANCE', - 'RECHECK', - 'RECORD', - 'RECURSIVE', - 'REDUNDANCY', - 'REDUNDANT', - 'REF', - 'REFERENCE', 'REFERENCES', - 'REFRESH', 'REGEXP', - 'REINDEX', - 'RELATIVE', 'RELEASE', - 'RELOAD', - 'RELY', - 'REMOTE', - 'REMOVE', 'RENAME', - 'REPAIR', - '_REPAIR_TABLE', 'REPEAT', - 'REPEATABLE', - '_REPL', - '_REPROVISIONING', 'REPLACE', - 'REPLICA', - 'REPLICATE', - 'REPLICATING', - 'REPLICATION', 'REQUIRE', - 'RESOURCE', - 'RESOURCE_POOL', - 'RESET', - 'RESTART', - 'RESTORE', 'RESTRICT', - 'RESULT', - '_RESURRECT', - 'RETRY', 'RETURN', - 'RETURNING', - 'RETURNS', - 'REVERSE', - 'RG_POOL', 'REVOKE', 'RIGHT', 'RIGHT_ANTI_JOIN', 'RIGHT_SEMI_JOIN', 'RIGHT_STRAIGHT_JOIN', 'RLIKE', - 'ROLES', - 'ROLLBACK', - 'ROLLUP', - 'ROUTINE', - 'ROW', - 'ROW_COUNT', - 'ROW_FORMAT', - 'ROW_NUMBER', - 'ROWS', - 'ROWSTORE', - 'RULE', - '_RPC', - 'RUNNING', - 'S3', - 'SAFE', - 'SAVE', - 'SAVEPOINT', - 'SCALAR', 'SCHEMA', 'SCHEMAS', - 'SCHEMA_BINDING', - 'SCROLL', - 'SEARCH', - 'SECOND', 'SECOND_MICROSECOND', - 'SECURITY', 'SELECT', 'SEMI_JOIN', - '_SEND_THREADS', 'SENSITIVE', 'SEPARATOR', - 'SEQUENCE', - 'SEQUENCES', - 'SERIAL', - 'SERIALIZABLE', - 'SERIES', - 'SERVICE_USER', - 'SERVER', - 'SESSION', - 'SESSION_USER', 'SET', - 'SETOF', - 'SECURITY_LISTS_INTERSECT', - 'SHA', - 'SHARD', - 'SHARDED', - 'SHARDED_ID', - 'SHARE', 'SHOW', - 'SHUTDOWN', 'SIGNAL', - 'SIGNED', - 'SIMILAR', - 'SIMPLE', - 'SITE', - 'SKIP', - 'SKIPPED_BATCHES', - '__SLEEP', 'SMALLINT', - 'SNAPSHOT', - '_SNAPSHOT', - '_SNAPSHOTS', - 'SOFT_CPU_LIMIT_PERCENTAGE', - 'SOME', - 'SONAME', - 'SPARSE', 'SPATIAL', - 'SPATIAL_CHECK_INDEX', 'SPECIFIC', 'SQL', 'SQL_BIG_RESULT', @@ -706,145 +206,50 @@ export const keywords = flatKeywordList({ 'SQL_CACHE', 'SQL_CALC_FOUND_ROWS', 'SQLEXCEPTION', - 'SQL_MODE', 'SQL_NO_CACHE', 'SQL_NO_LOGGING', 'SQL_SMALL_RESULT', 'SQLSTATE', 'SQLWARNING', - 'STDIN', - 'STDOUT', - 'STOP', - 'STORAGE', 'STRAIGHT_JOIN', - 'STRICT', - 'STRING', - 'STRIP', - 'SUCCESS', - 'SUPER', - 'SYMMETRIC', - 'SYNC_SNAPSHOT', - 'SYNC', - '_SYNC', - '_SYNC2', - '_SYNC_PARTITIONS', - '_SYNC_SNAPSHOT', - 'SYNCHRONIZE', - 'SYSID', - 'SYSTEM', 'TABLE', - 'TABLE_CHECKSUM', - 'TABLES', - 'TABLESPACE', - 'TAGS', - 'TARGET_SIZE', - 'TASK', - 'TEMP', - 'TEMPLATE', - 'TEMPORARY', - 'TEMPTABLE', - '_TERM_BUMP', - 'TERMINATE', 'TERMINATED', - 'TEXT', 'THEN', - 'TIME', - 'TIMEOUT', - 'TIMESTAMP', - 'TIMESTAMPADD', - 'TIMESTAMPDIFF', - 'TIMEZONE', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TO', - 'TRACELOGS', - 'TRADITIONAL', 'TRAILING', - 'TRANSFORM', - 'TRANSACTION', - '_TRANSACTIONS_EXPERIMENTAL', - 'TREAT', 'TRIGGER', - 'TRIGGERS', 'TRUE', - 'TRUNC', - 'TRUNCATE', - 'TRUSTED', - 'TWO_PHASE', - '_TWOPCID', - 'TYPE', - 'TYPES', 'UNBOUNDED', - 'UNCOMMITTED', - 'UNDEFINED', 'UNDO', - 'UNENCRYPTED', - 'UNENFORCED', - 'UNHOLD', - 'UNICODE', 'UNION', 'UNIQUE', - '_UNITTEST', - 'UNKNOWN', - 'UNLISTEN', - '_UNLOAD', 'UNLOCK', - 'UNLOGGED', - 'UNPIVOT', 'UNSIGNED', - 'UNTIL', 'UPDATE', - 'UPGRADE', 'USAGE', 'USE', - 'USER', - 'USERS', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', '_UTF8', - 'VACUUM', - 'VALID', - 'VALIDATE', - 'VALIDATOR', - 'VALUE', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARCHARACTER', - 'VARIABLES', - 'VARIADIC', 'VARYING', - 'VERBOSE', - 'VIEW', - 'VOID', - 'VOLATILE', - 'VOTING', - 'WAIT', - '_WAKE', - 'WARNINGS', - 'WEEK', 'WHEN', 'WHERE', 'WHILE', - 'WHITESPACE', 'WINDOW', 'WITH', - 'WITHOUT', 'WITHIN', - '_WM_HEARTBEAT', - 'WORK', - 'WORKLOAD', - 'WRAPPER', 'WRITE', - 'XACT_ID', 'XOR', - 'YEAR', 'YEAR_MONTH', - 'YES', 'ZEROFILL', - 'ZONE', ], }); diff --git a/test/singlestoredb.test.ts b/test/singlestoredb.test.ts index deac08e45a..a9e76e8ac8 100644 --- a/test/singlestoredb.test.ts +++ b/test/singlestoredb.test.ts @@ -79,4 +79,28 @@ describe('SingleStoreDbFormatter', () => { `); }); }); + + it('uppercases only reserved keywords', () => { + expect( + format( + `create table account (id int comment 'the most important column'); + select * from mysql.user; + insert into user (id, name) values (1, 'Blah');`, + { keywordCase: 'upper' } + ) + ).toBe(dedent` + CREATE TABLE + account (id INT comment 'the most important column'); + + SELECT + * + FROM + mysql.user; + + INSERT INTO + user (id, name) + VALUES + (1, 'Blah'); + `); + }); });