'프로그램 사용 > postgreSQL' 카테고리의 다른 글
| postgres table schema comment 달기 (0) | 2019.11.13 |
|---|---|
| with in sql (0) | 2019.11.11 |
| postgres unnest(null)을 조심하자 (0) | 2019.11.10 |
| array가 포함된 행을 여러개의 행으로 만들기 (0) | 2019.11.09 |
| array_agg에서 NULL 없애기 array_remove() (0) | 2019.11.06 |
| postgres table schema comment 달기 (0) | 2019.11.13 |
|---|---|
| with in sql (0) | 2019.11.11 |
| postgres unnest(null)을 조심하자 (0) | 2019.11.10 |
| array가 포함된 행을 여러개의 행으로 만들기 (0) | 2019.11.09 |
| array_agg에서 NULL 없애기 array_remove() (0) | 2019.11.06 |
git을 전송할때 압축하는데 서버측에서 메모리 부족으로 뻗을수 있으니
로컬에서 압축하지 않고 보내도록 하면 되는 듯?
| remote: Counting objects: 50044, done. remote: aborting due to possible repository corruption on the remote side. fatal: 프로토콜 오류: 잘못된 묶음 헤더 |
| Adding git config --global pack.window "0" worked for me...along with following git config --global pack.windowMemory "100m" git config --global pack.packSizeLimit "100m" git config --global pack.threads "1" Reason: Git clone compresses the data while cloning the repository It compresses the data on the server memory before receiving the data/files. If the server has out of memory you will get the above error while packing the objects You can fix the issue by making git clone the repository without packing the objects on the server with the following. git config --global pack.window "0" |
[링크 : https://stackoverflow.com/questions/4170317/git-pull-error-remote-object-is-corrupted]
| git 에서 push 하지 않은 commit 확인하기 (0) | 2019.11.23 |
|---|---|
| git 리비전 오가기 (0) | 2019.11.20 |
| git 저장소 합치기 (0) | 2019.06.03 |
| gitignore 특정 파일은 예외에서 제외시키기 (0) | 2019.04.17 |
| gitlab 서비스 명(centos) (0) | 2019.02.15 |
값을 추적하다 보니 몇개가 사라져서 역으로 찾다보니
unnest() 안에 들어가는 항목이 null 일 경우에는 (empty array가 아닌 null)
아예 해당 항목 자체가 select 되지 않는 문제가 존재한다.
해결법이 맞는진 모르겠지만..
null일 조건 비교해서 두번 선택해야 할지도?
(한번에 선택하는 법이 있으면 좋겠네)..
값을 비교해서 unnest 하거나, lateral join을 쓴다는데
lateral join을 아직 모르니.. 일단 값 비교 하는걸로 해야겠다.
(다만, case 에서 multiple row는 리턴하지 못하도록 되어있으니 주의)
[링크 : https://stackoverflow.com/questions/15175187/postgresql-unnest-with-empty-array]
[링크 : https://dba.stackexchange.com/questions/119201/how-does-unnest-treat-null-values-and-empty-arrays]
+
SQL 특성(?)인지 당연하게도 해당 내용이 있는지 확인하고
배열이 있으면 해당 배열을 unnest 하고
배열이 없으면 null 배열을 넣어서 처리하도록 하면 해결은 된다..
(null 배열이 아니라 해당 필드가 null 이기 때문에 발생한 경우는 해결 됨)
| WITH tbl(id, arr) AS ( VALUES (1, '{a}'::text[]) , (2, '{NULL}'::text[]) , (3, '{}'::text[]) , (4, '{x,y,z}'::text[]) ) SELECT id, elem FROM tbl t , unnest ( CASE WHEN array_length(t.arr, 1) >= 1 THEN t.arr ELSE '{null}'::text[] END ) elem; |
[링크 : https://dba.stackexchange.com/questions/119201/how-does-unnest-treat-null-values-and-empty-arrays]
| with in sql (0) | 2019.11.11 |
|---|---|
| where not in 에서는 null 값을 조심하자 (0) | 2019.11.11 |
| array가 포함된 행을 여러개의 행으로 만들기 (0) | 2019.11.09 |
| array_agg에서 NULL 없애기 array_remove() (0) | 2019.11.06 |
| drop extension (0) | 2019.11.01 |
sql이 항상 그렇지만.. 간편한 방법은 없고
해당 row에 대한 모든 필드를 적어주고, 늘릴 녀석을 unnest() 해주면 된다.
아래 링크는 데이터가 축하게도(!) 2개 뿐이니 select id, unnest(text::text[]) 로 하면 될 것 같지만
여러개면 일일이 다 적어주어야 하잖아? 크앙...
| id, text 001, {foo,boo,foo} 002, {"",for,test,friday} 003, {"","",test,friday,tuesday,foo,boo} |
| SELECT id, txt, count(*) As txt_count FROM ( SELECT id , unnest(txt) AS txt FROM tbl ) sub WHERE txt <> '' GROUP BY id, txt ORDER BY id, txt; |
[링크 : https://stackoverflow.com/questions/24209197/postgres-convert-array-of-elements-to-multiple-rows]
| where not in 에서는 null 값을 조심하자 (0) | 2019.11.11 |
|---|---|
| postgres unnest(null)을 조심하자 (0) | 2019.11.10 |
| array_agg에서 NULL 없애기 array_remove() (0) | 2019.11.06 |
| drop extension (0) | 2019.11.01 |
| pgcrypto 사용 예제 (0) | 2019.10.30 |
| SELECT objects.*, array_remove(array_agg(tags.tag), NULL) AS tags, FROM objects LEFT JOIN taggings ON objects.id = taggings.object_id LEFT JOIN tags ON tags.id = taggings.tag_id |
| postgres unnest(null)을 조심하자 (0) | 2019.11.10 |
|---|---|
| array가 포함된 행을 여러개의 행으로 만들기 (0) | 2019.11.09 |
| drop extension (0) | 2019.11.01 |
| pgcrypto 사용 예제 (0) | 2019.10.30 |
| postgresql 쿼리 수행속도 벤치마크 하기 (0) | 2019.10.30 |
| array가 포함된 행을 여러개의 행으로 만들기 (0) | 2019.11.09 |
|---|---|
| array_agg에서 NULL 없애기 array_remove() (0) | 2019.11.06 |
| pgcrypto 사용 예제 (0) | 2019.10.30 |
| postgresql 쿼리 수행속도 벤치마크 하기 (0) | 2019.10.30 |
| postgresql ctid (0) | 2019.10.29 |
확장기능 설치. database 하위의 extension에 pgcrypto가 추가되며
사용가능한 함수들은 public에 function 에 추가된다.
|
CREATE EXTENSION pgcrypto; |
binary 값으로 나오기 때문에 encode와 decode를 이용해서 출력하도록 하는 것으로 보임
|
-- 암호화 select encode(encrypt(convert_to('홍길동','utf8'),'ENC_KEY','aes'),'hex'); -- 복호화 select convert_from(decrypt(decode('encrypted_value','hex'),'ENC_KEY','aes'),'utf8'); -- 암호화 된 것을 검색하기 select mem_id, convert_from(decrypt(decode(mem_name,'hex'),'ENC_KEY','aes'),'utf8') from tb_test; |
[링크 : https://jully215.tistory.com/104]
문제는... 암호화하려면 해당 컬럼이 bytea 형식이 되어야 하는 듯?
| regress=# create table demo(pw bytea); CREATE TABLE regress=# insert into demo(pw) values ( encrypt( 'data', 'key', 'aes') ); INSERT 0 1 regress=# select decrypt(pw, 'key', 'aes') FROM demo; decrypt ------------ \x64617461 (1 row) regress=# select convert_from(decrypt(pw, 'key', 'aes'), 'utf-8') FROM demo; convert_from -------------- data (1 row) |
[링크 : https://dba.stackexchange.com/questions/24370/how-to-use-aes-encryption-in-postgresql]
| array_agg에서 NULL 없애기 array_remove() (0) | 2019.11.06 |
|---|---|
| drop extension (0) | 2019.11.01 |
| postgresql 쿼리 수행속도 벤치마크 하기 (0) | 2019.10.30 |
| postgresql ctid (0) | 2019.10.29 |
| coalesce() / isnull() (0) | 2019.10.29 |
for loop로 반복하기
[링크 : https://dba.stackexchange.com/questions/42012/how-can-i-benchmark-a-postgresql-query]
pgbench - 말그대로 벤치마크용 유틸리티. 테이블 생성등의 성능을 테스트 하는 듯
[링크 : https://severalnines.com/blog/benchmarking-postgresql-performance]
[링크 : https://www.postgresql.org/docs/10/pgbench.html]
+
mysql에는 benchmark()라는 함수로 지원함(반복 명령에 대한 매크로 느낌)
[링크 : http://www.mysqlkorea.com/sub.html?mcode=develop&scode=01&lang=k&m_no=21838...]
| drop extension (0) | 2019.11.01 |
|---|---|
| pgcrypto 사용 예제 (0) | 2019.10.30 |
| postgresql ctid (0) | 2019.10.29 |
| coalesce() / isnull() (0) | 2019.10.29 |
| 다른 테이블의 값을 이용하여 값 update 하기 (0) | 2019.10.28 |
ctid는 typle id로 물리적 위치를 나타내는데 update 하면 바뀐다고 한다(oracle 등은 고정된 순서로 유지되는 듯)
[링크 : https://www.postgresdba.com/bbs/board.php?bo_table=B12&wr_id=63]
|
ctid The physical location of the row version within its table. Note that although the ctid can be used to locate the row version very quickly, a row's ctid will change each time it is updated or moved by VACUUM FULL. Therefore ctid is useless as a long-term row identifier. The OID, or even better a user-defined serial number, should be used to identify logical rows. |
[링크 : https://www.postgresql.org/docs/8.2/ddl-system-columns.html]
| pgcrypto 사용 예제 (0) | 2019.10.30 |
|---|---|
| postgresql 쿼리 수행속도 벤치마크 하기 (0) | 2019.10.30 |
| coalesce() / isnull() (0) | 2019.10.29 |
| 다른 테이블의 값을 이용하여 값 update 하기 (0) | 2019.10.28 |
| array_agg()와 unnest() (0) | 2019.10.28 |
postgresql 에서는 isnull 대신 coalesce()를 지원한다고 한다.
용도는... full outer join 에서 한쪽이 null일 경우 반대쪽 key를 사용하는 용도 정도?
그 외에는 어떤 용도가 있을지 모르겠다.
설명만 봐서는.. nullif가 다른 dbms의 명령어와 같아 보이는데
coalesce는 value [,...] 이기 때문에 n개에 대해서 지원을 하는 것으로 보인다.
| COALESCE(value [, ...]) NULLIF(value1, value2) |
[링크 : https://www.postgresql.org/docs/9.5/functions-conditional.html]
[링크 : http://www.postgresqltutorial.com/postgresql-coalesce/]
| postgresql 쿼리 수행속도 벤치마크 하기 (0) | 2019.10.30 |
|---|---|
| postgresql ctid (0) | 2019.10.29 |
| 다른 테이블의 값을 이용하여 값 update 하기 (0) | 2019.10.28 |
| array_agg()와 unnest() (0) | 2019.10.28 |
| postgres tde pgcrypto (0) | 2019.10.25 |