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 구차니

centos 에다가 ubuntu 18.04를 깔았는데

예전에는 잘되던거 같더니만.. virt-manager에서 화면이 안나오고

cpu가 100% 떠서 demsg 확인해보니 아래와 같이 뜬다. (Xorg 죽일때 인 듯)

[ 1319.634237] [drm:qxl_release_from_id_locked [qxl]] *ERROR* failed to find id in release_idr

 

아무튼.. QXL 드라이버 관련 ubuntu에서 변경이 있었나..

kvm에서 QXL 말고 다른 드라이버를 쓰도록 해야하려나?

[링크 : https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/kvm-qxl-xorg-driver-4175548090/]

[링크 : https://www.reddit.com/r/archlinux/comments/7l7596/xorg_not_working_on_arch_kvm_guest/]

'프로그램 사용 > kvm(virt-manager)' 카테고리의 다른 글

중첩가상화  (0) 2023.06.16
kvm cpuinfo proc hide  (0) 2020.01.19
kvm/qemu 로그 위치  (0) 2019.10.07
kvm core 을 guest에 할당하기(affinity)  (0) 2019.08.28
virsh host only network  (0) 2019.07.09
Posted by 구차니

centos 7 기준 아래에 존재한다.

/var/log/libvirt/qemu

 

 

$ sudo grep -e 'starting up' -e 'shutting down' /var/log/libvirt/qemu/vmname-log

[링크 : https://serverfault.com/questions/830887/how-to-log-kvm-qemu-guest-boot-reboot-shutdown-time]

'프로그램 사용 > kvm(virt-manager)' 카테고리의 다른 글

kvm cpuinfo proc hide  (0) 2020.01.19
kvm ubuntu Xorg cpu 100% 문제  (0) 2019.10.10
kvm core 을 guest에 할당하기(affinity)  (0) 2019.08.28
virsh host only network  (0) 2019.07.09
vmdk를 qcow2로 변경하기  (2) 2019.07.09
Posted by 구차니

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

postgres 배열 처리하기  (0) 2019.10.15
sql with ,  (0) 2019.10.10
postgresql rank() over()  (0) 2019.10.04
여러 줄을 하나의 값으로 합치기 - array()  (0) 2019.10.02
postgresql LEFT JOIN = LEFT OUTER JOIN  (0) 2019.10.01
Posted by 구차니

중복되는 놈들이 있을때 값이 가장 큰 한놈만 빼서 쓰기 위해 사용한 함수.

그 외에는 어떤 목적으로 써야 하려나?

 

select (

SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary DESC) FROM empsalary;

) where rank = 1;

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

[링크 : https://www.postgresql.org/docs/9.1/tutorial-window.html]

Posted by 구차니

array 안에서는 select 문을 통해 다른 값들을 받아 하나의 필드로 출력을 해준다.

개꿀! (unnest로 풀면되지!)

 

The result I get is:

 +-----------------------+
 | ?column?              |
 +-----------------------+
 | 15:00:00 Dissertation |
 | 17:00:00 Dinner       |
 | 23:00:00 Sleep        |
 +-----------------------+
Now that I have my rows, I can turn them into an array.  Now, the ARRAY function needs to be invoked via a SELECT.  Thus, using ARRAY means that we’re using a subselect.  The inner SELECT is what we did above.  The outer one is just our call to ARRAY:

SELECT ARRAY(SELECT meeting_at::time || ' ' || description 
FROM Appointments 
WHERE meeting_at::date = '2014-may-23'
ORDER BY meeting_at);
And sure enough, we get a one-row, one-column result:

 +--------------------------------------------------------------+
 | array                                                        |
 +--------------------------------------------------------------+
 | {"15:00:00 Dissertation","17:00:00 Dinner","23:00:00 Sleep"} |
 +--------------------------------------------------------------+

[링크 : https://lerner.co.il/2014/05/23/turning-postgresql-rows-arrays-array/]

Posted by 구차니