내가 원하는건 아래의 예인데..

CROSS JOIN

 

I get: 
Col1 | Col2 | Col3 | Col4 | Col5  
--------------------------------- 
NULL | NULL | NULL |  2   |  0 
 7   |  3   |  4   | NULL | NULL 


I want to get 

Col1 | Col2 | Col3 | Col4 | Col5  
--------------------------------- 
  7  |  3   |   4  |  2   |  0

 

막상 쿼리를 보니 그냥 두개 합쳐서 골라서 빼내는 것 같네..

자동으로 null은 없애고 합치는건 없으려나?

SELECT B.Col1 
    ,B.col2 
    ,B.col3 
    ,A.col4 
    ,A.col5 
FROM ( 
    SELECT NULL AS Col1 
        ,NULL AS Col2 
        ,NULL AS Col3 
        ,2 AS Col4 
        ,0 AS Col5 
    ) A 
CROSS JOIN ( 
    SELECT 7 AS Col1 
        ,3 AS Col2 
        ,4 AS Col3 
        ,NULL AS Col4 
        ,NULL AS Col5 
    ) B

[링크 : https://stackoverflow.com/questions/36078353/sql-server-union-with-multiple-columns/36078940]

 

+

null을 없애고 합치는건 left join이 오히려 유용한건가?

[링크 : https://stackoverflow.com/questions/11461867/sql-cross-join-with-null-values]

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

query tweak join vs large table  (0) 2019.09.17
postgresql csv import null as null  (0) 2019.09.11
sql 여러행을 하나로 합치기 concat  (0) 2019.09.08
값별 갯수 통계  (0) 2019.09.07
postgresql.conf 설정사항들  (0) 2019.09.06
Posted by 구차니

oracle에서는 WM_CONCAT

mysql에서는 GROUP_CONCAT

postgresql 에서는 ARRAY_TO_STRING(ARRAY_AGG(column_name),',')  으로 하면 된다고 한다.

 

[링크 : https://dmsrbdi123.tistory.com/11] postgresql

[링크 : https://gent.tistory.com/15] oracle

[링크 : https://extbrain.tistory.com/48] mysql

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

postgresql csv import null as null  (0) 2019.09.11
cross join  (0) 2019.09.08
값별 갯수 통계  (0) 2019.09.07
postgresql.conf 설정사항들  (0) 2019.09.06
postgresql copy from csv , iso8859-1  (0) 2019.09.05
Posted by 구차니

distinct count만 생각했는데 group by를 써야하는 가였나..

 

위에는 distinct의 영향을 받아 order by column_name이 적용되고

아래는 order by가 적용되지 않는 순서로 나온다.(결과는 동일)

select distinct(column_name), count(*) from table group by(column_name)

select column_name, count(*) from table group by(column_name)

[링크 :https://stackoverflow.com/questions/7053902/sql-how-to-get-the-count-of-each-distinct-value-in-a-column]

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

cross join  (0) 2019.09.08
sql 여러행을 하나로 합치기 concat  (0) 2019.09.08
postgresql.conf 설정사항들  (0) 2019.09.06
postgresql copy from csv , iso8859-1  (0) 2019.09.05
postgresql copy from csv, date null  (0) 2019.09.05
Posted by 구차니

9시에 아부지가 차 가져와 주시고

12시 즘 겨우 되서 구리로 출발

12:30~2:30에 애들 상상노리에서 놀리고

지호 신발사고 돌아와서 피자 먹고

회사 오니 6시

언제가나...

'개소리 왈왈 > 육아관련 주저리' 카테고리의 다른 글

가족들 모두 골골골  (0) 2019.09.16
그래도 추석이라고 보름달인데  (2) 2019.09.13
딸래미 안과 다녀왔는데  (2) 2019.08.29
분노조절 실패모드  (0) 2019.08.24
오늘도 키즈카페  (2) 2019.08.18
Posted by 구차니

shared_buffers 기본 32M 이지만, 대략 서버 메모리 기준으로 1/4 ~ 1/2 정도로 할당

[링크 : http://hochul.net/blog/postgresql-configuration-tuning-basic-guide/?ckattempt=1]

 

work_mem 쿼리에 해당되는 정렬이나 임시 저장을 위한 공간 확보의 상한선 각 쿼리당으로 설정값이 반영

[링크 : https://arisu1000.tistory.com/1047]

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

sql 여러행을 하나로 합치기 concat  (0) 2019.09.08
값별 갯수 통계  (0) 2019.09.07
postgresql copy from csv , iso8859-1  (0) 2019.09.05
postgresql copy from csv, date null  (0) 2019.09.05
postgresql unknown pseudo-type  (0) 2019.09.05
Posted by 구차니
Hélias-Rodzewicz et al. Abstract# 9578,

요런 문구가 있어서, import에서 오류가 나는데..

오류:  "UTF8" 인코딩에서 사용할 수 없는 문자가 있음: 0xe9 0x6c 0x69

 

리눅스에서 file 명령으로 확인하면 이런식으로 인식을 한다.

UTF-8로 저장이 안되어서 그런가.. 아무튼 mobaxterm을 통해서 복사하면 위와 같이 첨자가 붙은 e로 인식을 하는데

BOM이 없어서 단순하게 ISO-8859-1로 인식하는건지 아니면 실제로

ISO-8859-1로 저장된걸 UTF-8로 인식하려다가 오류나는건진 모르겠다(아마도 전자에 가까울지도..)

.txt: ISO-8859 text, with very long lines

 

아무튼 해결책은 파일의 인코딩을 지정해 주면된다.

\COPY ... FROM 'file' DELIMITER E'\t' CSV HEADER ENCODING 'iso8859-1';

[링크 : https://stackoverflow.com/questions/30916853/postgresql-copy-encoding-how-to]

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

값별 갯수 통계  (0) 2019.09.07
postgresql.conf 설정사항들  (0) 2019.09.06
postgresql copy from csv, date null  (0) 2019.09.05
postgresql unknown pseudo-type  (0) 2019.09.05
postgresql schema 내의 테이블 이동하기  (0) 2019.09.05
Posted by 구차니

에러는 아래와 같이 났고..

오류:  date 자료형 대한 잘못된 입력: "NULL"

 

일단은 아래의 방식으로 회피, quote 쪽은 영향을 안주는 듯 하나 테스트는 안해봤음

DELIMITER E',' CSV QUOTE '"' NULL as 'NULL';

[링크 : https://www.postgresql.org/message-id/4938938A.2090409@dbginc.com]

[링크 : https://stackoverflow.com/questions/40428417/postgres-csv-date-null-import-error]

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

postgresql.conf 설정사항들  (0) 2019.09.06
postgresql copy from csv , iso8859-1  (0) 2019.09.05
postgresql unknown pseudo-type  (0) 2019.09.05
postgresql schema 내의 테이블 이동하기  (0) 2019.09.05
pgadmin over ssh  (0) 2019.09.03
Posted by 구차니
Linux2019. 9. 5. 13:34

소리 절로나오는 상황 -_-

 

cut -d'|' -f2- infile > outfile2 && mv outfile2 file

[링크 : https://stackoverflow.com/questions/16448153/awk-how-to-delete-first-column-with-field-separator]

 

여러개 필드를 날릴려면 -f2,4 이런식으로 리스트로 적어주면 된다.

       -f, --fields=LIST
              select only these fields;  also print any line that contains no delimiter character, unless the -s option is specified

'Linux' 카테고리의 다른 글

screen 명령어와 함께 실행하기  (0) 2019.09.23
screen 스크롤하기  (0) 2019.09.23
awk csv  (0) 2019.09.05
awk 변수 지정  (0) 2019.09.02
awk 치환(삭제)  (0) 2019.09.02
Posted by 구차니
Linux2019. 9. 5. 12:59

awk로 csv를 처리하려면.. 구분자를 , 로 하고 손을 봐야 하는데

영 매끄럽진 않네..

 

[링크 : https://www.joeldare.com/wiki/using_awk_on_csv_files]

'Linux' 카테고리의 다른 글

screen 스크롤하기  (0) 2019.09.23
csv에서는 awk 보단 cut  (0) 2019.09.05
awk 변수 지정  (0) 2019.09.02
awk 치환(삭제)  (0) 2019.09.02
tail과 cat 합치기  (0) 2019.09.02
Posted by 구차니

9.0 이후 부터 unknown을 쓸수 없게 되었다는데 도대체 이런 타입을 어떻게 만든거지?

 

unknown became a pseudo-type with commit d8d32d9a5. Creation of tables with unknown columns was disabled in commit 1e7c4bb004. Both commits were in January 2017, long after 9.0

[링크 : https://dba.stackexchange.com/questions/241870/postgres-column-type-unknown/241872#241872]

 

일단은.. text로 바꾸어주면 되려나?

[링크 : https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=1e7c4bb...]

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

postgresql copy from csv , iso8859-1  (0) 2019.09.05
postgresql copy from csv, date null  (0) 2019.09.05
postgresql schema 내의 테이블 이동하기  (0) 2019.09.05
pgadmin over ssh  (0) 2019.09.03
psql 명령어  (0) 2019.09.03
Posted by 구차니