'프로그램 사용/postgreSQL'에 해당되는 글 156건

  1. 2019.10.21 sql ' escape
  2. 2019.10.20 sql pivot / crosstab
  3. 2019.10.20 subquery
  4. 2019.10.18 array_agg() 여러개 컬럼 합치기
  5. 2019.10.16 postgresql vacuum
  6. 2019.10.16 pgadmin4 분석기능
  7. 2019.10.16 postgres regexp_matches() 매칭되는 것이 없을 경우
  8. 2019.10.15 sql 결과 공백 제거
  9. 2019.10.15 postgres 배열 처리하기
  10. 2019.10.10 sql with ,

'를 문장내에서 쓰기 위해서는

' '' ' 이렇게 하면 된다.

 

'' (홀따옴표 두개)

[링크 : https://kdarkdev.tistory.com/122]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

array_agg()와 unnest()  (0) 2019.10.28
postgres tde pgcrypto  (0) 2019.10.25
sql pivot / crosstab  (0) 2019.10.20
subquery  (0) 2019.10.20
array_agg() 여러개 컬럼 합치기  (0) 2019.10.18
Posted by 구차니

요렇게 여러개에 대해서 나열된 녀석들을

 

아래처럼 바꾸어주는걸 pivot이라고 표현하는데

위의 정보는 로그라는 느낌이라면, pivor으로 표현하면 먼가 전문적인 느낌이 든다?

아무튼.. 하나의 기준(여기서는 cdate)에 하나의 값 분류로 정렬한다.. 라고 하면 맞는걸까?

[링크 : https://splee75.tistory.com/110]

 

crosstab

[링크 : https://codeday.me/ko/qa/20190307/17921.html]

[링크 : https://www.postgresql.org/docs/9.1/tablefunc.html]

[링크 : http://www.gurubee.net/article/80779]

 

+

2019.10.21

crosstab 여러가지 방식이 있으나..

crosstab('데이터','컬럼명') 으로 하는게 가장 확실한 듯?

[링크 : https://yahwang.github.io/posts/76]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

postgres tde pgcrypto  (0) 2019.10.25
sql ' escape  (0) 2019.10.21
subquery  (0) 2019.10.20
array_agg() 여러개 컬럼 합치기  (0) 2019.10.18
postgresql vacuum  (0) 2019.10.16
Posted by 구차니

여러개의 행을 돌려주는 서브쿼리라는게 이 기능에 대한 카테고리일려나?

아무튼 아무생각 없이 쓰던 select where in 이 이 구문이라니..

 

[링크 : http://www.gurubee.net/lecture/1503]

[링크 : https://subscription.packtpub.com/book/big_data_and_business_intelligence/9781783989003/1/ch01lvl1sec16/subqueries-that-return-multiple-rows]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

sql ' escape  (0) 2019.10.21
sql pivot / crosstab  (0) 2019.10.20
array_agg() 여러개 컬럼 합치기  (0) 2019.10.18
postgresql vacuum  (0) 2019.10.16
pgadmin4 분석기능  (0) 2019.10.16
Posted by 구차니

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

sql pivot / crosstab  (0) 2019.10.20
subquery  (0) 2019.10.20
postgresql vacuum  (0) 2019.10.16
pgadmin4 분석기능  (0) 2019.10.16
postgres regexp_matches() 매칭되는 것이 없을 경우  (0) 2019.10.16
Posted by 구차니

vacuum full 을 하면 db 끊고

다시 복사해서 새로운 데이터베이스로 생성하면서

용량을 줄이는 등의 최적화를 하고

 

vacuum verbose analyze 를 하면 간략하게 끊지 않고도 할 수 있다고 한다.

 

다만 디스크 스토리지 줄이는건 full만 된다고.

 

[링크 : https://blog.gaerae.com/2015/09/postgresql-vacuum-fsm.html]

[링크 : https://bstar36.tistory.com/308]

 

아래의 명령으로 자동 정리가 켜져있는지 확인가능하다고 한다.

show autovacuum;

[링크 : http://hochul.net/blog/postgresql-vacuum-optimization/?ckattempt=1]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

subquery  (0) 2019.10.20
array_agg() 여러개 컬럼 합치기  (0) 2019.10.18
pgadmin4 분석기능  (0) 2019.10.16
postgres regexp_matches() 매칭되는 것이 없을 경우  (0) 2019.10.16
sql 결과 공백 제거  (0) 2019.10.15
Posted by 구차니

explain analyze

전에 어떻게 쓰는법 찾았다가 까먹은건가.. 기억이 잘 안나네..

 

+

아래 링크는 개발버전

[링크 : https://www.pgadmin.org/docs/pgadmin4/development/query_tool.html]

 

요게 현재최신 버전. 여기서는 위에 처럼 다양하게 나오진 않는다.

[링크 : https://www.pgadmin.org/docs/pgadmin4/4.13/query_tool.html]

Posted by 구차니

regexp_matches()를 select에서 쓸 경우

해당 매치가 되지 않는 항목에 대해서는 버려진다 -ㅁ-!

즉, 1000개 중에 매칭되지 않는게 200개가 있으면

800개만 나오는데

매치 되지 않는 녀석들을 뽑아 내려면 아래와 같은 트릭을 쓰면 된다고 한다.

일단은 나의 경우에는 null 이었고, null을 내보내 주긴 하는데 값이 있는데 매칭이 안되는건 모르겠네?

with test_data as (
  select 'abc 123' as txt
  union
  select 'abc 456' as txt
  union
  select 'blah' as txt
)

select
  txt,
  (select regexp_matches(txt, '\d+'))[1] as first_num
from
  test_data

[링크 : https://dba.stackexchange.com/questions/210047/postgres-return-default-value-if-regex-match-fails]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

postgresql vacuum  (0) 2019.10.16
pgadmin4 분석기능  (0) 2019.10.16
sql 결과 공백 제거  (0) 2019.10.15
postgres 배열 처리하기  (0) 2019.10.15
sql with ,  (0) 2019.10.10
Posted by 구차니

trim() 으로 하면 끝

옵션은 많지만 일단 앞뒤로 알아서 잘라주는 듯?

 

[링크 : https://araikuma.tistory.com/523]

[링크 : https://www.postgresql.org/docs/9.4/functions-string.html]

[링크 : http://www.postgresqltutorial.com/postgresql-trim-function/]

Posted by 구차니

일단 쿼리는 아래처럼

SELECT (refid::bigint[])[array_length(refid::bigint[], 1)], refid::bigint[] FROM array_table
where rowid = 8;

 

해당 필드에는 아래의 값이 text로 저장되어 있는데

{42457771,42457772,42457773,42457774,42457775,42457776,42457777,42474803,42477457,42487546,42491301}

 

refid::bigint[] 를 통해서 array로 캐스팅 하고

()[] 를 통해서 해당 위치의 값을 가져오도록 한다.

넣는 순서대로 되서 max 값은 가장 뒤에 일테니,

"" ""

array_length(refid::bigint[].1) 을 통해서 가장 마지막 인덱스를 얻도록 하고

인덱스로 부터 가져오면 성공!

42491301

[링크 : https://www.postgresql.org/docs/9.4/functions-array.html]

 

text로 저장된 녀석을 배열로 되살리기

select '{1,1}'::int[]

[링크 : https://stackoverflow.com/questions/47359288/convert-a-text-to-an-array-postgresql]

 

array_agg 함수에서 정렬해서 넣기

SELECT array_agg(a ORDER BY b DESC) FROM table;

[링크 : https://stackoverflow.com/questions/7317475/postgresql-array-agg-order]

Posted by 구차니
Posted by 구차니