Cute Happy Ghost
본문 바로가기
728x90
SMALL

DB47

postgresql 소수점 뒤로 두자리 나오도록, 소수점 0 표시, to_char 0표시 select bacteria ,to_char(bacteria, 'FM999.90') ,to_char(bacteria, 'FM999.990') from .. 순서대로 이런 결과가 나옴 나는 소수점뒤로 두자리가 나왔으면 좋겠어서 fm990.90을 썼다 2022. 5. 27.
postgresql DB에있는 모든 컬럼 조회 및 테이블별 정렬, 해당 테이블 컬럼조회 DB에있는 모든 컬럼 조회 및 테이블별 정렬 SELECT TABLE_NAME as 테이블이름, column_name as 컬럼명, is_nullable as null가능여부, data_type as 데이터타입, character_maximum_length as 최대길이, character_octet_length, numeric_precision, numeric_precision_radix, numeric_scale FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = 'DB이름' and table_schema = '스키마이름' ORDER BY 테이블이름, ORDINAL_POSITION; 예) public스키마의 test데이터베이스내의 tableA의 모든 컬럼명만.. 2022. 5. 25.
[postgresql] null 체크하는 방법, null 데이터 문자열로 치환 - COALESCE 함수 SELECT bacteria , virus FROM data_table ; data_table에서 값을 표출하고싶은데 null값이 들어가니까 화면에 undefined로 떴다 이건 막아야해...! java단에서 처리해주려고 했는데 null값이라서 그런지 아예 list에 키값도 뜨지 않았다... 그래서 쿼리에서 null값처리할 수 있는 방법이 있을까 찾아봤는데 역시나! 방법은 있었다 SELECT , COALESCE(bacteria, '-99') as "bacteria" , COALESCE(virus , '-99') as "virus" FROM data_table COALESCE( 칼럼명 , 바꿀데이터)를 사용해주면 됨 2022. 5. 24.
vscode로 ERD 만들기, ERD Editor , erd 무료 툴 추천 https://marketplace.visualstudio.com/items?itemName=dineug.vuerd-vscode ERD Editor - Visual Studio Marketplace Extension for Visual Studio Code - ERD Editor vscode extension marketplace.visualstudio.com ERD툴에 도무지 정착을 못하는 나... 매번 프로젝트할 때마다 ERD툴 찾아다니는 나.. VScode에 이런 플러그인이 있는지는 몰랐지!!!! 저거 해서 install받으면 됨. 확장자는 {어쩌구}.vuerd.json 로 파일을 생성하면 된다. 이렇게 Open ERD Editor로 연다 테이블 생성 마우스 오른쪽 클릭해서 new table 클릭 .. 2022. 3. 31.
POSTGRESQL 테이블명세서 테이블정의서 추출 쿼리 SELECT info. TABLE_NAME, info. COLUMN_NAME, info.udt_name as type, case when info.character_maximum_length is null then info.numeric_precision else info.character_maximum_length end as length, info.column_default, info.is_nullable, comm.column_comment as comment, case when pri_key.column_name is null then '' else 'PK' end as PK FROM information_schema. COLUMNS info LEFT JOIN ( SELECT PS.schemana.. 2021. 12. 21.
해당문자열 다른문자열로 치환 update문 tableA에서 ㈜ < 특수문자들을 (주) 2021. 12. 16.
postgresql 실행중인 쿼리 확인, lock된 쿼리문 강제종류 실행중인 쿼리 조회 lock된 쿼리문의 pid확인 SELECT * FROM pg_stat_activity ORDER BY query_start ASC; 쿼리문 강제종료 put 조회한 pid SELECT pg_cancel_backend(pid); 2021. 12. 2.
mybatis collection size 길이 체크, null체크 mybatis에서 collection을 사용해야하는데 만약 collection이 null이라면 다른 조건을 실행해야 할 때 if나 when을 써서 test ="info != null and info.size != 0" 이런식으로 하면 null check 완료 info는 collection 이름.. select tcc.comm_nm as "rcy_cd" ,tfi.fclt_nm as "fclt_nm" ,th.old_valas "oldValue" ,th.new_val as "value" ,th.mdfy_resn AS "mdfy_resn" ,th.user_id AS "user_id" ,TO_CHAR(th.reg_date, 'yyyy-mm-dd')AS "reg_date" from t_hist_life_mrs th.. 2021. 11. 15.
[postgresql] case when true false 조건에 따라 출력하는법, 중복방지 글쓰기 where 절에 있는 조건의 애들이 맞는 데이터들이 0개면 false 아니면 true ajax를 써서 false면 글을 쓸 수 있게 true면 글작성이 안되게 select CASE WHEN count(*) = 0 THEN false ELSE true END from t_record_amt_life_rcy where sgg_cd = #{sgg} and fclt_year =#{fclt_year} 2021. 11. 15.
postgresql count여러개 보기 각 카테고리별 항목수 확인 ratio_stdr_cd에 각각 RS00101,RS00102,RS00103,RS00104,RS00105가 있는데 얘네의 데이터들이 몇개나 있는지 확인할 때 쿼리 하나만 쓰는게 아니라 한번에 보고싶을 때 쓰는 쿼리 filter 사용 select * from t_ratio_cd trc ; select count(1) filter (where ratio_stdr_cd = 'RS00101') as "RS00101", count(1) filter (where ratio_stdr_cd = 'RS00102') as "RS00102", count(1) filter (where ratio_stdr_cd = 'RS00103') as "RS00103", count(1) filter (where ratio_stdr_cd = .. 2021. 11. 15.
728x90
LIST