MySQL에서 ‘a’ = ‘a ‘가 true로 평가된다? | 우아한형제들 기술블로그
{{item.name}} DB 알못의 어떤 리서치 개요 안녕하세요 기계인간 이종립입니다. FC플랫폼개발팀에서 배민찬 백엔드를 개발하고 있습니다. DB알못인 저는 업무 중에 우연히 MySQL에서 'a' = 'a '의 결과가
techblog.woowahan.com
https://dev.mysql.com/doc/refman/5.6/en/char.html
MySQL :: MySQL 5.6 Reference Manual :: 11.3.2 The CHAR and VARCHAR Types
11.3.2 The CHAR and VARCHAR Types The CHAR and VARCHAR types are similar, but differ in the way they are stored and retrieved. They also differ in maximum length and in whether trailing spaces are retained. The CHAR and VARCHAR types are declared with a l
dev.mysql.com
When CHAR values are stored, they are right-padded with spaces to the specified length.
When CHAR values are retrieved, trailing spaces are removed unless the PAD_CHAR_TO_FULL_LENGTH SQL mode is enabled.
- CHAR 값을 저장할 때는, 정의된 길이를 맞추기 위해 오른쪽에 공백(들)을 붙입니다.
- CHAR 값을 가져올 때는, 따라붙인 공백은 제거합니다.
- (PAD_CHAR_TO_FULL_LENGTH 모드가 비활성화된 경우)
ValueCHAR(4)Storage RequiredVARCHAR(4)Storage Required'''ab''abcd''abcdefgh'
' ' | 4 bytes | '' | 1 byte |
'ab ' | 4 bytes | 'ab' | 3 bytes |
'abcd' | 4 bytes | 'abcd' | 5 bytes |
'abcd' | 4 bytes | 'abcd' | 5 bytes |
'DB(SQL)' 카테고리의 다른 글
[DB] 로그파일 분할 (feat. Docker) (0) | 2022.12.08 |
---|---|
[SQL] where 절 작성시 조심해야하는 것 (feat. null) (0) | 2022.09.26 |
[DB] 책 (0) | 2022.05.12 |
[공부해야할것] Database 단편화 (feat. DB 서버 성능저하) (0) | 2022.05.02 |
[DB] Materialized View (구체화 뷰/ 물리적 뷰) (0) | 2021.10.06 |