Spring boot JPA에서 DB 예약어를 column으로 사용하는 방법
목차
1. Database 별 예약어
2. Spring boot JPA에서 예약어 사용하는 방법
Database 별 예약어
아래는 각 데이터베이스의 공식 홈페이지에 서술된 예약어입니다. 이 포스팅에 모두 추가하려고 했으나, mariadb와 postgresql은 내용이 너무 많아 링크만 추가했습니다.
1) oracle
docs.oracle.com/cd/B19306_01/server.102/b14200/ap_keywd.htm#i690190
ACCESS, ADD, ALL, ALTER, AND, ANY, AS, ASC, AUDIT, BETWEEN, BY, CHAR, CHECK, CLUSTER, COLUMN, COMMENT, COMPRESS, CONNECT, CREATE, CURRENT, DATE, DECIMAL, DEFAULT, DELETE, DESC, DISTINCT, DROP, ELSE, EXCLUSIVE, EXISTS, FILE, FLOAT, FOR, FROM, GRANT, GROUP, HAVING, IDENTIFIED, IMMEDIATE, IN, INCREMENT, INDEX, INITIAL, INSERT, INTEGER, INTERSECT, INTO, IS, LEVEL, LIKE, LOCK, LONG, MAXEXTENTS, MINUS, MLSLABEL, MODE, MODIFY, NOAUDIT, NOCOMPRESS, NOT, NOWAIT, NULL, NUMBER, OF, OFFLINE, ON, ONLINE, OPTION, OR, ORDER, PCTFREE, PRIOR, PRIVILEGES, PUBLIC, RAW, RENAME, RESOURCE, REVOKE, ROW, ROWID, ROWNUM, ROWS, SELECT, SESSION, SET, SHARE, SIZE, SMALLINT, START, SUCCESSFUL, SYNONYM, SYSDATE, TABLE, THEN, TO, TRIGGER, UID, UNION, UNIQUE, UPDATE, USER, VALIDATE, VALUES, VARCHAR, VARCHAR2, VIEW, WHENEVER, WHERE, WITH
2) mssql
docs.microsoft.com/ko-kr/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-server-ver15docs.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-server-ver15&viewFallbackFrom=sql-server-ver15%EF%BB%BF
ADD, EXTERNAL, PROCEDURE, ALL, FETCH, PUBLIC, ALTER, FILE, RAISERROR, AND, FILLFACTOR, READ, ANY, FOR, READTEXT, AS, FOREIGN, RECONFIGURE, ASC, FREETEXT, REFERENCES, AUTHORIZATION, FREETEXTTABLE, REPLICATION, BACKUP, FROM, RESTORE, BEGIN, FULL, RESTRICT, BETWEEN, FUNCTION, RETURN, BREAK, GOTO, REVERT, BROWSE, GRANT, REVOKE, BULK, GROUP, RIGHT, BY, HAVING, ROLLBACK, CASCADE, HOLDLOCK, ROWCOUNT, CASE, IDENTITY, ROWGUIDCOL, CHECK, IDENTITY_INSERT, RULE, CHECKPOINT, IDENTITYCOL, SAVE, CLOSE, IF, SCHEMA, CLUSTERED, IN, SECURITYAUDIT, COALESCE, INDEX, SELECT, COLLATE, INNER, SEMANTICKEYPHRASETABLE, COLUMN, INSERT, SEMANTICSIMILARITYDETAILSTABLE, COMMIT, INTERSECT, SEMANTICSIMILARITYTABLE, COMPUTE, INTO, SESSION_USER, CONSTRAINT, IS, SET, CONTAINS, JOIN, SETUSER, CONTAINSTABLE, KEY, SHUTDOWN, CONTINUE, KILL, SOME, CONVERT, LEFT, STATISTICS, CREATE, LIKE, SYSTEM_USER, CROSS, LINENO, TABLE, CURRENT, LOAD, TABLESAMPLE, CURRENT_DATE, MERGE, TEXTSIZE, CURRENT_TIME, NATIONAL, THEN, CURRENT_TIMESTAMP, NOCHECK, TO, CURRENT_USER, NONCLUSTERED, TOP, CURSOR, NOT, TRAN, DATABASE, NULL, TRANSACTION, DBCC, NULLIF, TRIGGER, DEALLOCATE, OF, TRUNCATE, DECLARE, OFF, TRY_CONVERT, DEFAULT, OFFSETS, TSEQUAL, DELETE, ON, UNION, DENY, OPEN, UNIQUE, DESC, OPENDATASOURCE, UNPIVOT, DISK, OPENQUERY, UPDATE, DISTINCT, OPENROWSET, UPDATETEXT, DISTRIBUTED, OPENXML, USE, DOUBLE, OPTION, USER, DROP, OR, VALUES, DUMP, ORDER, VARYING, ELSE, OUTER, VIEW, END, OVER, WAITFOR, ERRLVL, PERCENT, WHEN, ESCAPE, PIVOT, WHERE, EXCEPT, PLAN, WHILE, EXEC, PRECISION, WITH, EXECUTE, PRIMARY, WITHIN GROUP, EXISTS, PRINT, WRITETEXT, EXIT, PROC,
3) mariadb
mariadb.com/kb/en/reserved-words/
4) PostgreSQL
www.postgresql.org/docs/13/sql-keywords-appendix.html
Spring boot JPA에서 예약어 사용하는 방법
spring boot 프로젝트는 기본적으로 resources 폴더에 application.properties 또는 application.yml 파일이 있습니다. 이 파일에 내용을 추가하면 됩니다.
1) application.properties
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
2) application.yml
spring:
jpa:
properties:
hibernate:
globally_quoted_identifiers: true
위와 같이 설정 후, show sql을 하면 DB별로 다르지만, 오라클 기준 큰 따옴표(")으로 감싸져 query가 실행되어 예약어를 사용 가능한 것을 알 수 있습니다.