본문 바로가기

DB스토리

(30)
PostgreSQL 날짜 연산 펌 - http://ntalbs.github.io/2010/postgresql-date/간단한 날짜 관련 함수 및 날짜 연산:-- 오늘 (date)select current_date;-- 현재시각 (timestamp)select now();select current_timestamp;-- 어제/오늘/내일select current_date - 1 "어제", current_date "오늘", current_date + 1 "내일";-- day of weekselect extract(dow from current_date); -- 일요일(0) ~ 토요일(6)select extract(isodow from current_date); -- 월요일(1) ~ 일요일(7)-- day of yearselect extra..
다중로우 배열로 변경 처리 /* SELECT array_to_string(array_agg([컬럼]),'[구분자]') */ SELECT array_to_string(array_agg(column),',') >> aaa,bbb,ccc/* arry_agg() 만 쓰면 배열 형식으로 표현됨 */ /* {aaa,bbb} 이런식.. */ 출처: http://mcpaint.tistory.com/211 [MC빼인트와 함께]
postgresql merge query withupsertas(select 20 as user_id,'aaa' as hidden_columns, 50 as rows, 'bbb' as key, 'ccc' as default_columns),update_optionas(update config.users_info as u1 set hidden_columns = 'aaa',default_columns = 'ccc' from upsert where user_id = upsert.user_id and key = upsert.key)insert into config.users_info select upsert.user_id, upsert.hidden_columns, upsert.rows, upsert.key, upsert.default_columns f..
Postgresql 9.3. 산술 함수와 연산자 표 9-2. 산술 연산자연산자 이름설명예제결과+덧셈2 + 35-뺄셈2 - 3-1*곱2 * 36/나누기 (정수의 나눗셈에서 나머지를 절단)4 / 22%나머지 (정수의 나눗셈에서 나머지) 5 % 41^거듭제곱2.0 ^ 3.08|/제곱근|/ 25.05||/세제곱 근||/ 27.03!계승5 !120!!계승 (전치 연산자)!! 5120@절대값@ -5.05&이진 AND91 & 1511|이진 OR32 | 335#이진 XOR17 # 520~이진 NOT~1-2> 22 이진 연산자는 내부 데이터 형식에만 사용할 수 있습니다. 반면 다른 연산자는 모든 숫자 데이터 형식에 사용할 수 있습니다. 또한 이진 연산자는 표 9-10 에 나타내는 bit, bit varying 비트 문자열에 대해서도 사용할 수 있습니다. 표 9-3에 ..
postgresql 메뉴얼 사이트 https://www.postgresql.org/docs/manuals/ http://yeobi27.tistory.com/entry/PostgreSQL-%EC%A0%9C%EC%95%BD%EC%A1%B0%EA%B1%B4-ConstraintNOT-NULL-UNIQUE-PRIMARY-KEY%EA%B8%B0%EB%B3%B8%ED%82%A4-FOREIGN-KEY%EC%99%B8%EB%9E%98%ED%82%A4
PostgreSQL 문자열 함수와 연산자 표 9-5. SQL 문자열 함수와 연산자함수반환 값 형식설명例 예제結果결과string || stringtext문자열 결합'Post' || 'greSQL'PostgreSQL문자열 || 비 문자열 또는 비 문자열 || 문자열text하나가 비문자열인 입력 문자열 결합'Value: ' || 42Value: 42bit_length( string )int문자열의 비트수bit_length('jose')32char_length( string ) 또는 character_length( string )int문자열의 문자 수char_length('jose')4lower( string )text문자열을 소문자로 변환lower('TOM')tomoctet_length( string )int문자열의 바이트 수octet_length(..
Postgresql 지원 툴 #모델링 툴 @SQL POWER ARCHITECT http://www.sqlpower.ca/page/splash
mysql 계층 쿼리 MANAGING HIERARCHICAL DATA IN MYSQLIntroductionMost users at one time or another have dealt with hierarchical data in a SQL database and no doubt learned that the management of hierarchical data is not what a relational database is intended for. The tables of a relational database are not hierarchical (like XML), but are simply a flat list. Hierarchical data has a parent-child relationship that ..