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

DB/Postgresql22

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.
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.
728x90
LIST