티스토리 뷰

Study

postgresql(포스트그레스퀄) 관련

메디츠 2024. 2. 11. 05:24
반응형

17년 2월 기준.

 

to_char(to_timestamp(createtime/1000), 'YYYY/MM/DD HH24:MI:SS')

// bitint date타입 변환

 

SELECT * FROM TABLE_NAME LIMIT 10;

// 처음 10개의 Row를 반환

 

SELECT * FROM TABLE_NAME LIMIT 10 OFFSET 0;

// 처음(OFFSET 0) 10개의 Row를 반환

 

SELECT * FROM TABLE_NAME LIMIT 10 OFFSET 10;

// 11번째 부터 10개의 Row를 반환

 

TO_CHAR(STARTTIME,'YYYY/MM')

column "stat_call_hour.starttime" must appear in the GROUP BY clause or be used in an aggregate function

GROUP BY CONCAT(TO_CHAR(STARTTIME,'YYYY/MM'))

// SELECT 하는 것만큼 GROUP BY 해야 한다.

 

select status from (

select 1 status from user where id = 'admin' and password = 'admin'

union all

select 2 status from user where id = 'admin'

union all

select 3 status

)a limit 1;

// 아이디 패스워드 맞으면 1, 패스워드 틀리면 2, 다 틀리면 3

 

select session_user, current_user;

// 세션 유저, 현재 유저 확인

 

select nextval('rps_cluster_info_seq');

// sequence 값 증가.

select currval('rps_cluster_info_seq');

// sequence 값 받아오기. nextval 실행해서 세션을 얻어야 실행된다.

select setval('rps_cluster_info_seq', 1);

// sequence 값 초기화.

 

select extract(epoch from now())::bigint

// bigint로 현재 시간 받기

 

select * from alert where createtime<extract(epoch from now()-interval '1 day')::bigint*1000;

// bigint 비교시 변환후 * 1000을 해야 됨. now()에서 간격조절은 -interval로 가능

 

select TO_CHAR(TO_TIMESTAMP(bigint_field / 1000), 'DD/MM/YYYY HH24:MI:SS')

// bigint를 timestamp로 변환

 

pg_dump.exe --file "../backup/stat_call_hour" --host "192.168.100.239" --port "5435" --username "postgres" --no-password --verbose --format=c --blobs --table "public.stat_call_hour" "WebNmsDB"

// pg_dump로 db 백업

 

 

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2026/02   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
글 보관함