Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 코로나블루
- array_prepend
- 트랜드로드
- tvn shift
- 의존성검색
- 직지아모르마네트
- 검사예외
- su option
- 비검사예외
- logrotate error
- 심리학도서
- 파이어운동
- array_cat
- text[]
- 인수공통감염병
- 부의인문학
- ANY(
- ControllerAdvice
- 불렛저널책
- constructor injection
- field injection
- array_append
- Spring기초
- 메모독서법
- Cardinality
- 코로나불안증
- fire운동
- 라이더캐롤
- trend road
- 독후감
Archives
- Today
- Total
야생토끼 블로그
[postgreSQL] text array 형 where 절 조건 본문
postgreSQL arrays 타입이 있고
https://www.postgresql.org/docs/9.5/arrays.html
Arrays
PostgreSQL allows columns of a table to be defined as variable-length multidimensional arrays. Arrays of any built-in or user-defined base type, enum type, or composite type can be created. Arrays of domains are not yet supported. To illustrate the use of
www.postgresql.org
이중 text[] 타입의 쿼리 사용하게되었다.
8.15.5 Searching in Arrays 부분에서
text array 값들 중에서 10000인 값이 포함된지 찾는 방법은 아래와 같은 쿼리도 있지만
SELECT * FROM sal_emp WHERE pay_by_quarter[1] = 10000 OR pay_by_quarter[2] = 10000 OR pay_by_quarter[3] = 10000 OR pay_by_quarter[4] = 10000;
이 같은 방식으로도 가능하다.
SELECT * FROM sal_emp WHERE 10000 = ANY (pay_by_quarter);
또 text array 값 모두가 10000인 값을 찾을 때는 아래의 쿼리
SELECT * FROM sal_emp WHERE 10000 = ALL (pay_by_quarter);
주어진 array와 하나라도 겹치는 지 검색은 아래와 같이 가능하다
SELECT * FROM sal_emp WHERE pay_by_quarter && ARRAY [10000];
아래와 같은 함수도 추후 사용할 수 있을 것 같다.
SELECT array_prepend (1, ARRAY [2,3]); // {1,2,3}
SELECT array_append (ARRAY [1,2], 3); // {1,2,3}
SELECT array_cat (ARRAY [1,2], ARRAY [3,4]); //{1,2,3,4}
cardinality(schedule) // return the total numberr of elements
array_length(schedule, 1) //return the length of a specified array dimension
SELECT array_dims(ARRAY[1,2] || 3); //return a text representation of array's dimensions.
Comments