Postgresql split 하는방법

DB/Postgresql|2021. 8. 16. 12:44

특정 문자열을 기준으로 split할때 split_part 함수를 사용합니다.

 

select split_part(dong,' ',1),split_part(dong,' ',2),split_part(dong,' ',3),dong from trade

'DB > Postgresql' 카테고리의 다른 글

Postgresql 칼럼 추가 방법  (0) 2021.08.16
Postgresql db 버전확인  (0) 2021.08.16
Postgresql rownum 사용하기  (0) 2021.08.16
PostgreSQL Drop column  (0) 2021.08.15
[mac] postgresql 외부접속 가능하게 변경  (0) 2021.08.15

댓글()

Postgresql 칼럼 추가 방법

DB/Postgresql|2021. 8. 16. 11:52

apt_info 테이블에 acode 칼럼을 추가하는 방법 입니다.

alter table apt_info add column acode varchar(13);

'DB > Postgresql' 카테고리의 다른 글

Postgresql split 하는방법  (0) 2021.08.16
Postgresql db 버전확인  (0) 2021.08.16
Postgresql rownum 사용하기  (0) 2021.08.16
PostgreSQL Drop column  (0) 2021.08.15
[mac] postgresql 외부접속 가능하게 변경  (0) 2021.08.15

댓글()

Postgresql db 버전확인

DB/Postgresql|2021. 8. 16. 11:23

아래와 같은 명령어를 입력합니다.

select version()

 

실행결과

version PostgreSQL 13.3 on x86_64-apple-darwin20.4.0, compiled by Apple clang version 12.0.5 (clang-1205.0.22.9), 64-bit

 

'DB > Postgresql' 카테고리의 다른 글

Postgresql split 하는방법  (0) 2021.08.16
Postgresql 칼럼 추가 방법  (0) 2021.08.16
Postgresql rownum 사용하기  (0) 2021.08.16
PostgreSQL Drop column  (0) 2021.08.15
[mac] postgresql 외부접속 가능하게 변경  (0) 2021.08.15

댓글()

Postgresql rownum 사용하기

DB/Postgresql|2021. 8. 16. 09:50

오라클의 rownum을 Postgresql 에서 사용하기 위해서는 아래와 같이 사용하시면 됩니다.

 

select * ​​​​, 100 + (row_number () over()) as rownum from apt_info where lcode = '4785025623'

 

[실행결과]

 

행정코드 행정코드5자리 아파트명 동1 동2 rownum
4785025623 47850 칠곡남율효성해링턴플레이스1단지 석적읍 남율리 101
4785025623 47850 효성해링턴 플레이스 석적읍 남율리 102
4785025623 47850 효성해링턴플레이스2단지 석적읍 남율리 103
4785025623 47850 남율2지구 효성해링턴플레이스2차 석적읍 남율리 104
4785025623 47850 남광하우스토리 석적읍 남율리 105
4785025623 47850 동화공단타운 석적읍 남율리 106
4785025623 47850 효성해링턴플레이스(3단지) 석적읍 남율리 107
4785025623 47850 한솔 솔파크 강변 석적읍 남율리 108
4785025623 47850 우방신천지 석적읍 남율리 109
4785025623 47850 효성해밍턴플레이스3차 석적읍 남율리 110
4785025623 47850 한솔솔파크강변 석적읍 남율리 111

 

'DB > Postgresql' 카테고리의 다른 글

Postgresql 칼럼 추가 방법  (0) 2021.08.16
Postgresql db 버전확인  (0) 2021.08.16
PostgreSQL Drop column  (0) 2021.08.15
[mac] postgresql 외부접속 가능하게 변경  (0) 2021.08.15
[mac] postgresql 서비스 시작/종료  (0) 2021.08.15

댓글()

PostgreSQL Drop column

DB/Postgresql|2021. 8. 15. 17:54

테이블에서 칼럼을 삭제하는 방법 입니다.

ALTER TABLE table_name DROP COLUMN column_name;

 

칼럼이 존재하는지 확인한후 삭제하는 방법 입니다.

ALTER TABLE table_name DROP COLUMN IF EXISTS column_name;

'DB > Postgresql' 카테고리의 다른 글

Postgresql db 버전확인  (0) 2021.08.16
Postgresql rownum 사용하기  (0) 2021.08.16
[mac] postgresql 외부접속 가능하게 변경  (0) 2021.08.15
[mac] postgresql 서비스 시작/종료  (0) 2021.08.15
windows 에 PostgreSQL 설치  (0) 2021.08.05

댓글()

[mac] postgresql 외부접속 가능하게 변경

DB/Postgresql|2021. 8. 15. 11:31

[mac] postgresql 외부접속 가능하게 변경

 

설정파일이 있는 디렉토리로 이동합니다.

cd /usr/local/var/postgres

 

vi editor로 설정파일을 오픈합니다.

vi postgresql.conf

 

listen_addresses = '*' 외부에서 접속 가능하도록 설정을 변경합니다.

... 중략 ... # - Connection Settings - listen_addresses = '*' # what IP address(es) to listen on; ... 중략 ...

 

ssl off 설정을 추가합니다.

vi pg_hba.conf

가장 마지막 줄에 아래 내용을 입력합니다.

host all all 0.0.0.0/0 md5
위와 같이 설정하지 않으면 아래와 유사한 오류가 발생합니다.
 [1342] FATAL:  no pg_hba.conf entry for host "x.x.x.x", user "aptdb", database "postgres", SSL off

'DB > Postgresql' 카테고리의 다른 글

Postgresql rownum 사용하기  (0) 2021.08.16
PostgreSQL Drop column  (0) 2021.08.15
[mac] postgresql 서비스 시작/종료  (0) 2021.08.15
windows 에 PostgreSQL 설치  (0) 2021.08.05
PostgreSQL 테이블 생성  (0) 2021.08.04

댓글()

[mac] postgresql 서비스 시작/종료

DB/Postgresql|2021. 8. 15. 11:21

[mac] postgresql 서비스 시작

pg_ctl -D /usr/local/var/postgres start

 

[mac] postgresql 서비스 종료

pg_ctl -D /usr/local/var/postgres stop

 

댓글()

windows 에 PostgreSQL 설치

DB/Postgresql|2021. 8. 5. 18:46

windows 에 PostgreSQL 설치

 

아래 사이트에서 윈도우용 PostgreSQL을 다운로드 받습니다.

https://www.postgresql.org/download/windows/

 

PostgreSQL: Windows installers

Windows installers Interactive installer by EDB Download the installer certified by EDB for all supported PostgreSQL versions. This installer includes the PostgreSQL server, pgAdmin; a graphical tool for managing and developing your databases, and StackBui

www.postgresql.org

 

다운로드 받은 파일을 클릭하여 설치를 진행합니다.

 

설치시 로케일 부분을 Korean,Korea로 지정해 줍니다.

전아래와 같은 설정으로 설치를 진행했습니다.

Installation Directory: C:\Program Files\PostgreSQL\12 Server Installation Directory: C:\Program Files\PostgreSQL\12 Data Directory: C:\Program Files\PostgreSQL\12\data Database Port: 5432 Database Superuser: postgres Operating System Account: NT AUTHORITY\NetworkService Database Service: postgresql-x64-12 Command Line Tools Installation Directory: C:\Program Files\PostgreSQL\12 pgAdmin4 Installation Directory: C:\Program Files\PostgreSQL\12\pgAdmin 4 Stack Builder Installation Directory: C:\Program Files\PostgreSQL\12

 

댓글()

PostgreSQL 테이블 생성

DB/Postgresql|2021. 8. 4. 23:56

PostgreSQL 테이블 생성

 

먼저 유저로 로그인

postgres=# \c aptdb aptdb

 

테이블 생성

aptdb=# CREATE TABLE test ( id integer, name character varying(255)); CREATE TABLE

 

생성된 테이블 확인

aptdb=# \dt ​​​​​​​List of relations ​Schema | Name | Type | Owner --------+------+-------+------- ​public | test | table | aptdb (1 row)

댓글()

PostgreSQL 사용자 권한 생성 및 사용자 생성

DB/Postgresql|2021. 8. 4. 23:31

PostgreSQL 사용자 권한 생성 및 사용자 생성

postgreSQL 접속

psql postgres

\du 명령어를 입력합니다.

postgres=# \du

실행결과

​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​List of roles ​Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- ​goodsaem | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

goodsaem 유저의 패스워드를 변경합니다.

postgres=# \password goodsaem Enter new password: Enter it again:

 

신규 유저 생성

CREATE USER aptdb PASSWORD 'aptdb' SUPERUSER;

신규 유저로 로그인

psql postgres -U aptdb

데이터베이스 생성

CREATE DATABASE aptdb;

생성된 DB 확인

postgres=# \l

실행결과

postgres=# \l ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​List of databases ​​​Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+---------+-------+----------------------- ​aptdb | aptdb | UTF8 | C | C | ​postgres | goodsaem | UTF8 | C | C | ​template0 | goodsaem | UTF8 | C | C | =c/goodsaem + ​​​​​​​​​​​| | | | | goodsaem=CTc/goodsaem ​template1 | goodsaem | UTF8 | C | C | =c/goodsaem + ​​​​​​​​​​​| | | | | goodsaem=CTc/goodsaem (4 rows)

'DB > Postgresql' 카테고리의 다른 글

[mac] postgresql 외부접속 가능하게 변경  (0) 2021.08.15
[mac] postgresql 서비스 시작/종료  (0) 2021.08.15
windows 에 PostgreSQL 설치  (0) 2021.08.05
PostgreSQL 테이블 생성  (0) 2021.08.04
Mac 맥에 PostgresSQL 설치하기  (0) 2021.08.04

댓글()