ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [SQL] SQL 의 modifier: Keyword
    데이터 분석/DB & SQL 2020. 4. 25. 11:17

    ORDER BY clause 의 모든 것.


    ORDER BY 
    year 
    ASC NULLS FIRST,
    count 
    DESC NULLS FRIST


    ORDER BY 와 함께 사용되는 Modifier 는 다음과 같다: ASC (default), DESC, NULLS FIST, NULLS LAST (default)
    보라색 단어가 바로 Modifier, 정식 명칭으로는 SQL 이 지정한 Keyword 이다.

    We can also flip the order of the values returned by ORDER BY by using the modifier DESC

    There is also a modifier ASC for ordering data. 
    ASC is used in ORDER BY clauses to indicate that the results should be sorted in ascending order. However it is a redundant modifier as ascending order is the default for SQL.

    If there are cells in the table with NULL values, they are included in your sort and by default show up last. If you want to force them to show up first, add the modifier NULLS FIRST either after the column name or after DESC if you’re sorting in descending order.

     

     

     

    Q1. modifier 가 뭘까?

    A1. 영어 문법 상의 modifier [출처]

    A modifier is a word/phrase/clause which modifies other words in a sentence. To be specific, a modifier is either an adjective or an adverb. The adjectives modify the nouns, and the adverbs modify the verbs or the adjectives or the other adverbs.

    문장 안에서 다른 단어를 modify: 수식하는 단어/구절/구문이다. 구체적으로 modifier 는 형용사나 부사이다. 형용사는 명사를 수식하고, 부사는 동사, 형용사, 또는 다른 부사를 수식한다. 

    modifier 가 쓰는 위치에 따라 Pre-modifier 와 Post-modifier 로 구분한다.

    e.g. Generally, the brown dogs are nice.
    e.g. Stark, our teacher, gives us tasks to do in the class.

     

    A2. SQL 문법 상의 modifier 는 정의된 개념이 아니다. 대신 Keywordsreserved words 가 있다. [MySQL 8.0 기준 출처]

    Keywords are words that have significance in SQL. Certain keywords, such as SELECT, DELETE, or BIGINT, are reserved and require special treatment for use as identifiers such as table and column names. This may also be true for the names of built-in functions.

    Keywords 는 SQL 문법상 지정된 키워드로, 다른맥락에서 사용을 제한하는 reserved words 치다. 즉, SQL 문법이 아닌 맥락에서 사용할 경우에는 (예를 들어 테이블명 컬럼명 등을 지칭하는 identifiers) ' ' 와 같은 처리가 필요하다. 빌트인 함수도 키워드로 일반적으로는 지정되어있다. (지정되지 않은 빌트인 함수도 있지만)

     

     

    Q2. by default 정책은?

    modifier 가 지정되지 않았을 때 기본전제로 실행되는 키워드이다.

     

     

    결론. SQL 은 (굳이 따지자면) Post-modifier 이다.

    컬럼명 뒤에 modifier 가 오니까. 그래서 이런 modifier 위치에 따른 혼란이 없다. 

    squinting misplaced modifier 

     

    댓글

Designed by Tistory.