๐ PostgreSQL ๊ธฐ๋ณธ โ ค - ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ณ ๋ด๋ณด๋ด๊ธฐ
๐ PostgreSQL ๊ธฐ๋ณธ โ
ค - ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ณ ๋ด๋ณด๋ด๊ธฐ
๐
ใ์ค์ฉ SQLใ
์ ์ฝ๊ณ ์ ๋ฆฌํ ๊ธ์ ๋๋ค.
๊ฐ์
- ๊ตฌ๋ถ๋ ํ
์คํธ ํ์ผ์ ๋ฐ์ดํฐ๊ฐ ์๋ ๊ฒฝ์ฐ
PostgreSQL
์COPY
๋ช ๋ น์ ํตํด ๋๋์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค. PostgreSQL
์ ์ฉ์ธCOPY
๋ช ๋ น์๋ ์ด์ ํฌํจํ๊ฑฐ๋ ์ ์ธํ๊ณ ๋ค์ํ ๊ตฌ๋ถ๋ ํ ์คํธ ํ์ ์ ์ฒ๋ฆฌํ๋ ์ต์ ์ด ํฌํจ๋์ด ์๋ค.- ๋ฐ๋๋ก
COPY
๋ ํ ์ด๋ธ ๋๋ ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌ๋ถ๋ ํ ์คํธ ํ์ผ๋ก ๋ด๋ณด๋ด๊ธฐ๋ ํ๋ค. - ์ด ๊ธฐ์ ์ ๋๋ฃ์ ๋ฐ์ดํฐ๋ฅผ ๊ณต์ ํ๊ฑฐ๋ ์์ ํ์ผ๊ณผ ๊ฐ์ ๋ค๋ฅธ ํ์์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ฎ๊ธฐ๋ ๊ฒฝ์ฐ์ ์ ์ฉํ๋ค.
- ์ผ๋ฐ์ ์ผ๋ก ๋ค์ ๊ณผ์ ์ ๋ฐ๋ฅธ๋ค.
- ๊ตฌ๋ถ๋ ํ ์คํธ ํ์ผ ํ์์ ์์ค ๋ฐ์ดํฐ๋ฅผ ์ค๋น
- ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ํ ์ด๋ธ ์์ฑ
COPY
์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ์ฌ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
- ์ฐธ๊ณ ๋ก
Microsoft
์์ธ์ค ๋๋MySQL
๊ณผ ๊ฐ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์์PostgreSQL
๋ก ์ง์ ๋ฐ์ดํฐ๋ฅผ ์ฎ๊ธฐ๋ ค๋ฉด ์๋ํํฐ ๋๊ตฌ๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.
๊ตฌ๋ถ๋ ํ ์คํธ ํ์ผ์ ์ด์ฉํ์ฌ ์์ ํ๊ธฐ
- ๊ตฌ๋ถ๋ ํ ์คํธ ํ์ผ์์๋ ๋ฐ์ดํฐ ํ์ด ํฌํจ๋์ด ์์ผ๋ฉฐ, ๊ฐ ํ์ ํ ์ด๋ธ์ ํ ํ์ ๋ํ๋ธ๋ค.
- ๊ฐ ํ์์ ๋ฌธ์๋ ๊ฐ๊ฐ์ ๋ฐ์ดํฐ ์ด์ ๋ถ๋ฆฌํ๊ฑฐ๋ ๊ตฌ๋ถํ๋ค.
- ์ผํ๊ฐ ๊ฐ์ฅ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉ๋๋ฉฐ, ๋ฐ๋ผ์ ์์ฃผ ๋ณผ ์ ์๋ ํ์ผ์ ์ผํ๋ก ๋ถ๋ฆฌ๋ ๊ฐ์ ์๋ฏธํ๋
CSV
ํ์ผ์ด๋ค.
ํค๋ ํ ์ฒ๋ฆฌํ๊ธฐ
- ๊ตฌ๋ถ๋ ํ ์คํธ ํ์ผ์๋ ๋ณดํต ํค๋ ํ์ด ํฌํจ๋๋ค.
- ํค๋ ํ์ ๊ฐ ์ด์ ๋ฐ์ดํฐ๋ฅผ ์๋ณํ๋ ๋ฐ ์ฌ์ฉ๋๋ฉฐ, ์ผ๋ถ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ด๋ฆฌ์๋ ํค๋ ํ์ ์ฌ์ฉํ์ฌ ๊ตฌ๋ถ๋ ํ์ผ์ ์ด์ ๊ฐ์ ธ์ค๊ธฐ ํ ์ด๋ธ์ ์ฌ๋ฐ๋ฅธ ์ด์ ๋งคํํ๋ค.
- ๊ทธ๋ฌ๋
PostgreSQL
๋ ํค๋ ํ์ ์ฌ์ฉํ์ง ์๋๋ค. - ๋ฐ๋ผ์ ํค๋ ํ์ ์ ์ธํ๊ธฐ ์ํด
COPY
๋ช ๋ น์์ ํน์ ์ต์ ์ ์ฌ์ฉํ๋ค.
ํฐ๋ฐ์ดํ๋ก ๋ฌถ์ ๊ฐ ์ฝ์ด์ค๊ธฐ
- ์ผํ๋ฅผ ์ด ๊ตฌ๋ถ ๊ธฐํธ๋ก ์ฌ์ฉํ๋ ๊ฒฝ์ฐ๋ ์ ์ฌ์ ์ธ ๋๋ ๋ง๊ฐ ๋์ฌ๋ฆฌ๊ณ ์๋ค.
- ๊ฐ๋ น โ์๋ ํ์ธ์, ์๊ธฐ์๊ฐ์ ๋๋ค.โ์ ๊ฐ์ด ์ด์ ๊ฐ์ ์ผํ๊ฐ ํฌํจ๋์ด ์๋ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํ ๊น?
- ์ด๋ฐ ๊ฒฝ์ฐ ๊ตฌ๋ถ ๊ธฐํธ๊ฐ ํฌํจ๋ ์ด์ ํ
์คํธ ํ์ ์๋ผ๋ ์์์ ๋ฌธ์๋ก ๊ฐ์ธ
SQL
์ ํฌํจ๋ ๊ตฌ๋ถ ๊ธฐํธ๋ฅผ ๋ฌด์ํ๋๋ก ์ง์ํ๋ค. - ๋๋ถ๋ถ ๊ตฌ๋ถ๋ ํ์ผ์์ ์ฌ์ฉํ๋ ํ ์คํธ ํ์ ์๋ ํฐ๋ฐ์ดํ์ด๋ค.
- ๊ธฐ๋ณธ์ ์ผ๋ก
PostgreSQL
์ ๊ธฐ๋ณธ์ ์ผ๋ก ํฐ๋ฐ์ดํ๋ก ๋ฌถ์ธ ์ด ์์ ๊ตฌ๋ถ ๊ธฐํธ๋ฅผ ๋ฌด์ํ์ง๋ง, ๊ฐ์ ธ์ค๊ธฐ์ ํ์ํ ๊ฒฝ์ฐ ๋ค๋ฅธ ํ ์คํธ ํ์ ์๋ฅผ ์ง์ ํ ์ ์๋ค. - ๋ง์ง๋ง์ผ๋ก
PostgreSQL
์ ๋ค์๊ณผ ๊ฐ์ด ํฐ๋ฐ์ดํ๋ก ๋ฌถ์ธ ์ด ์์์ ํ ์คํธ ํ์ ์๊ฐ ๋ ๋ฒ ์ฐ์์ผ๋ก ๋์ค๋ฉด ํ๋๋ฅผ ์ ๊ฑฐํ๋ค.
1
2
3
4
5
# PostgreSQL์ด ์ฝ์ ์ด
"123 Main St."" Apartment 200"
# PostgreSQL์ด ์ฒ๋ฆฌํ ์ด
123 Main St." Apartment 200
COPY
๋ฅผ ์ฌ์ฉํด ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
1
2
3
COPY table_name
FROM 'C:\directory\file.csv'
WITH (FORMAT CSV, HEADER);
- ๋จผ์ ์์ค ํ์ผ์ ์ด๊ณผ ๋ฐ์ดํฐ ํ์ ์ ํ์ธํ๊ณ ๊ทธ ๋ฐ์ดํฐ๋ฅผ ๋ณด๊ดํ ํ ์ด๋ธ์ ๋ง๋ค์ด์ผ ํ๋ค.
- ์ฝ๋๋
COPY
ํค์๋๋ก ์์ํ์ฌ ๋์ ํ ์ด๋ธ์ ์ด๋ฆ์ด ๋ค๋ฐ๋ฅธ๋ค. FROM
ํค์๋๋ ์ด๋ฆ์ ํฌํจํ์ฌ ์์ค ํ์ผ์ ์ ์ฒด ๊ฒฝ๋ก๋ฅผ ์๋ณํ๋ค.- ์ด์์ฒด์ ์ ๋ฐ๋ผ ๊ฒฝ๋ก ๋ฌธ์์ด์ ํ์์ด ๋ค๋ฅด๋ค.
WITH
ํค์๋๋ ์ํ๋ ์ต์ ์ ๊ดํธ๋ก ๊ฐ์ธ ์ ๋ ฅํ๊ฑฐ๋, ์ถ๋ ฅ ํ์์ ๋ง๊ฒ ์กฐ์ ํ ์ ์๋ ์ต์ ์ ์ง์ ํ๋ค.- ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉํ ์ต์ ์ ๋ค์๊ณผ ๊ฐ๋ค.
- ์
๋ ฅ ๋ฐ ์ถ๋ ฅ ํ์ผ ํ์
FORMAT
ํค์๋๋ฅผ ํตํด ์ฝ๊ฑฐ๋ ์ฐ๋ ํ์ผ์ ํ์์ ์ง์ ํ๋ค.- ํ์ผ ํ์์๋
CSV
,TEXT
,BINARY
๋ฑ์ด ์๋ค.
- ํค๋ ํ ํฌํจ ์ฌ๋ถ
- ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ๋
HEADER
ํค์๋๋ฅผ ์ฌ์ฉํ์ฌ ์์ค ํ์ผ์ ์ ์ธ ํ ํค๋ ํ์ด ์์์ ์ง์ ํ๋ค. - ๋ด๋ณด๋ผ ๋๋
HEADER
๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฐ์ดํฐ๋ฒ ์ด์ค๊ฐ ํค๋ ํ์ ํฌํจํ๋๋ก ์ง์ํ๋ค.
- ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ๋
- ๊ตฌ๋ถ ๊ธฐํธ
DELIMITER
ํค์๋๋ฅผ ํตํด ๊ฐ์ ธ์ค๊ธฐ ๋๋ ๋ด๋ณด๋ด๊ธฐ ํ์ผ์์ ๊ตฌ๋ถ์๋ก ์ฌ์ฉํ ๋ฌธ์๋ฅผ ์ง์ ํ๋ค.
- ์ธ์ฉ ๋ฌธ์
QUOTE
ํค์๋๋ฅผ ํตํด ํฐ๋ฐ์ดํ๊ฐ ์๋ ํ ์คํธ ํ์ ์๋ฅผ ์ง์ ํ ์ ์๋ค.
์นด์ดํฐ ์ธ๊ตฌ์กฐ์ฌ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
- ์ง๊ธ ์ฌ์ฉํ ๋ฐ์ดํฐ๋ ์ธ๊ตฌ์กฐ์ฌ์ ์ฐ๊ฐ ์ธ๊ตฌ ์ถ์ ์น์ด๋ค.
- ์ด๋ค์ ์ต๊ทผ์ 10๋ ์ธ๊ตฌ ์กฐ์ฌ๋ฅผ ํตํด ์ถ์๊ณผ ์ฌ๋ง, ๊ตญ๋ด ๋ฐ ๊ตญ์ ์ด์ฃผ๋ฅผ ๊ณ ๋ คํ์ฌ ๋งค๋ ๊ตญ๊ฐ์ ์ฃผ, ์นด์ดํฐ ๋ฐ ๊ธฐํ ์ง์ญ์ ์ธ๊ตฌ ์ถ์ ์น๋ฅผ ์ฐ์ถํ๋ค.
us_counties_pop_est_2019
ํ
์ด๋ธ ๋ง๋ค๊ธฐ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
CREATE TABLE us_counties_pop_est_2019 (
state_fips text,
county_fips text,
region smallint,
state_name text,
county_name text,
area_land bigint,
area_water bigint,
internal_point_lat numeric(10,7),
internal_point_lon numeric(10,7),
pop_est_2018 integer,
pop_est_2019 integer,
births_2019 integer,
deaths_2019 integer,
international_migr_2019 integer,
domestic_migr_2019 integer,
residual_2019 integer,
CONSTRAINT counties_2019_key PRIMARY KEY (state_fips, county_fips)
);
์ธ๊ตฌ ์กฐ์ฌ ๋ฐ์ดํฐ ์ด๊ณผ ๋ฐ์ดํฐ ํ์ ์ดํดํ๊ธฐ
- ์กด์ฌํ๋ค๋ฉด, ๋ฐ์ดํฐ ์ฌ์ ์ ํ์ธํ๊ฑฐ๋ ์จ๋ผ์ธ์ ํตํด ๋ฐ์ดํฐ๋ฅผ ํ์ธํ๋ ๊ฒ์ด ์ค์ํ๋ค.
state_fips
,county_fips
๋ฑ ์ฝ๋ ๊ฐ์ ์ ์๋ก ์ ์ฅํ๋ฉด 0์ผ๋ก ์์๋๋ ์ฝ๋๊ฐ ๋ง๊ฐ์ง ์ ์์ผ๋ฏ๋กtext
ํ์ ์ ์ฌ์ฉํด์ผ ํ๋ค.- ๋ํ ์ด ๊ฐ๋ค๋ก ๊ณ์ฐ์ ์ํํ ์ผ๋ ์๋ค.
region
์๋ 1์์ 4๊น์ง์ ์ซ์๊ฐ ์ ์ฅ๋๋ฏ๋กsmallint
ํ์ ์ผ๋ก ์ด์ ์ ์ํ๋ค.state_name
,county_name
์๋text
ํ์ ์ ์ฌ์ฉํ๋ค.- ์นด์ดํฐ์ ์๋ ํ ์ง์ ๋ฌผ์ ๋ํ ๋ฉด์ ์
area_land
,area_water
์ ๊ธฐ๋ก๋๋ค. - ์ด ๋์ ํฉ์น๋ฉด ์นด์ดํฐ์ ์ ์ฒด ๋ฉด์ ์ ๊ตฌํ ์ ์๋ค.
- ์๋์ค์นด์ฒ๋ผ ๋์ด ์๋ฉ ์์ธ ์ง์ญ์
integer
ํ์ ์ ์ต๋๊ฐ์ ๋๊ธธ ๊ฐ๋ฅ์ฑ์ด ๋์ผ๋ฏ๋กbigint
ํ์ ์ ์ฌ์ฉํ๋ค. internal_point_lat
,internal_point_lon
์ ๊ฐ๊ฐ ๋ด์ ์ ์๋์ ๊ฒฝ๋๋ฅผ ๋ํ๋ธ๋ค.- ์ธ๊ตฌ์กฐ์ฌ๊ตญ์ ๋ด์ ์ ๊ธฐ๋กํ ๋ ์์์ ์ดํ 7์๋ฆฌ๊น์ง ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์, ์ ์ ๋ถ๋ถ์ ์ต๋๊ฐ์ธ 180๊น์ง ์ฌ์ฉํ๋ ค๋ฉด ํ์ํ ์๋ฆฟ์๋ ์ด 10์๋ฆฌ๋ค.
- ๊ทธ๋ฌ๋ฏ๋ก
numeric(10, 7)
์ ์ฌ์ฉํ๋ค.
COPY
๋ก ์ธ๊ตฌ์กฐ์ฌ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
1
2
3
COPY us_counties_pop_est_2019
FROM 'C:\YourDirectory\us_counties_pop_est_2019.csv'
WITH (FORMAT CSV, HEADER);
Docker
๋ฅผ ์ฌ์ฉํ๋ค๋ฉดdocker cp us_counties_pop_est_2019.csv postgres-practice:/tmp/my_data.csv
๋ช ๋ น์ด๋ฅผ ํตํด ์ปจํ ์ด๋์ ํ์ผ์ ๋๊ฒจ์ผ ํ๋ค.
1
2
3
4
5
6
7
Updated Rows 3142
Execute time 0.032s
Start time Fri Aug 15 21:09:42 KST 2025
Finish time Fri Aug 15 21:09:42 KST 2025
Query COPY us_counties_pop_est_2019
FROM 'C:\YourDirectory\us_counties_pop_est_2019.csv'
WITH (FORMAT CSV, HEADER)
๊ฐ์ ธ์จ ๋ฐ์ดํฐ ๊ฒ์ฌํ๊ธฐ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- ๋ชจ๋ ์ด๊ณผ ํ ์กฐํ
SELECT * FROM us_counties_pop_est_2019;
-- area_land ๊ฐ์ด ํฐ ์ธ ๊ฐ์ ํ ์กฐํ
SELECT county_name, state_name, area_land
FROM us_counties_pop_est_2019
ORDER BY area_land DESC
LIMIT 3;
-- internal_point_lon ๊ฐ์ด ํฐ ๋ค์ฏ ๊ฐ์ ํ ์กฐํ
SELECT county_name, state_name, internal_point_lat, internal_point_lon
FROM us_counties_pop_est_2019
ORDER BY internal_point_lon DESC
LIMIT 5;
COPY
๋ฅผ ์ฌ์ฉํ์ฌ ์ด ํ์ ์งํฉ ๊ฐ์ ธ์ค๊ธฐ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
CREATE TABLE supervisor_salaries (
id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
town text,
county text,
supervisor text,
start_date text,
salary numeric(10,2),
benefits numeric(10,2)
);
-- ์ค๋ฅ ๋ฐ์
COPY supervisor_salaries
FROM 'C:\YourDirectory\supervisor_salaries.csv'
WITH (FORMAT CSV, HEADER);
-- CSV ํ
์ด๋ธ ์ด ์ง์
COPY supervisor_salaries (town, supervisor, salary)
FROM 'C:\YourDirectory\supervisor_salaries.csv'
WITH (FORMAT CSV, HEADER);
- ํ
์ด๋ธ ์์ฑ ํ
COPY
ํค์๋๋ฅผ ํตํดCSV
๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์์ผ ํ๋ค. - ๋ค๋ง ํ
์ด๋ธ ์ด์ ๋ฐ๋ก ์ง์ ํ์ง ์์ผ๋ฉด
DB
๋ด ํ ์ด๋ธ ์ด์ ์ฒซ ๋ฒ์งธ ์ด์ธid
๊ฐ์ดCSV
์๋ ์์ผ๋ฏ๋ก ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค. - ๊ทธ๋ฌ๋ฏ๋ก
COPY
ํค์๋ ์ฌ์ฉ ์CSV
ํ ์ด๋ธ์ ์ด๋ ์ง์ ํด์ผ ํ๋ค.
1
2
3
4
5
6
7
Updated Rows 5
Execute time 0.012s
Start time Fri Aug 15 21:18:33 KST 2025
Finish time Fri Aug 15 21:18:33 KST 2025
Query COPY supervisor_salaries (town, supervisor, salary)
FROM 'C:\YourDirectory\supervisor_salaries.csv'
WITH (FORMAT CSV, HEADER)
1
SELECT * FROM supervisor_salaries ORDER BY id LIMIT 2;
- ๋ฐ์ดํฐ๋ฅผ ํ์ธํ๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
id | town | county | supervisor | start_date | salary | benefits |
---|---|---|---|---|---|---|
1 | Anytown | ย | Jones | ย | 67,000 | ย |
2 | Bumblyburg | ย | Larry | ย | 74,999 | ย |
COPY
๋ฅผ ์ฌ์ฉํ์ฌ ํ์ ์ผ๋ถ๋ง ๊ฐ์ ธ์ค๊ธฐ
1
2
3
4
5
6
COPY supervisor_salaries (town, supervisor, salary)
FROM 'C:\YourDirectory\supervisor_salaries.csv'
WITH (FORMAT CSV, HEADER)
WHERE town = 'New Brillig';
SELECT * FROM supervisor_salaries;
WHERE
ํค์๋๋ฅผ ํตํด ํน์ ์กฐ๊ฑด์ ํด๋นํ๋ ํ๋ง ๊ฐ์ ธ์ฌ ์ ์๋ค.
๊ฐ์ ธ์ค๋ ๊ณผ์ ์์ ์ด์ ๊ฐ ์ถ๊ฐํ๊ธฐ
CSV
ํ์ผ์ ์นด์ดํฐ ์ด์Mills
๋ผ๋ ์ด๋ฆ์ด ์๋๋ฐ, ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋ ๊ณผ์ ์์ ๊ทธ ๊ฐ์ด ํ์ํ๋ค๋ ๊ฑธ ์๊ฒ ๋๋ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํ ๊น?- ๋ฐ๋ก
CSV
ํ์ผ์ ๊ฐ์ ธ์ค๊ธฐ ์ ์ ์์ ํ ์ด๋ธ์ ๋ก๋ํ๋ ๊ฒ์ด๋ค. - ์์ ํ ์ด๋ธ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ธ์ ์ ์ข ๋ฃํ๊ธฐ ์ ๊น์ง๋ง ์กด์ฌํ๋ฏ๋ก ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ค์ ์ด๊ฑฐ๋ ์ฐ๊ฒฐ์ ๋์ผ๋ฉด ํด๋น ํ ์ด๋ธ์ ์ฌ๋ผ์ง๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
CREATE TEMPORARY TABLE supervisor_salaries_temp
(LIKE supervisor_salaries INCLUDING ALL);
COPY supervisor_salaries_temp (town, supervisor, salary)
FROM 'C:\YourDirectory\supervisor_salaries.csv'
WITH (FORMAT CSV, HEADER);
INSERT INTO supervisor_salaries (town, county, supervisor, salary)
SELECT town, 'Mills', supervisor, salary
FROM supervisor_salaries_temp;
DROP TABLE supervisor_salaries_temp;
- ์์ ํ
์ด๋ธ๋ก
CSV
๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์์, ํด๋น ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋กcount
์ด์ ๊ฐ์Mills
๋ก ๋ฐ๊พผ ๊ฐ์ ์๋ณธ ํ ์ด๋ธ์ ์ฝ์ ํ๋ค. - ์ดํ ์์ ํ ์ด๋ธ์ ์ญ์ ํ๋ค.
- ๋ฌผ๋ก ์ง์ ์ญ์ ํ์ง ์์๋ ์ฐ๊ฒฐ์ด ๋์ด์ง ๊ฒฝ์ฐ ์๋์ผ๋ก ์ฌ๋ผ์ง์ง๋ง, ๋ค๋ฅธ
CSV
ํ์ผ์ ๊ฐ์ ธ์ ์๋ก์ด ์์ ํ ์ด๋ธ์ ์ฌ์ฉํ๋ ค๋ ๊ฒฝ์ฐ ์ด๋ ๊ฒ ์ญ์ ํด์ฃผ์ด์ผ ํ๋ค. SELECT * FROM supervisor_salaries ORDER BY id LIMIT 2;
๋ฅผ ํตํด ๋ฐ์ดํฐ๋ฅผ ํ์ธํ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ๋ค.
id | town | county | supervisor | start_date | salary | benefits |
---|---|---|---|---|---|---|
21 | Anytown | Mills | Jones | ย | 67,000 | ย |
22 | Bumblyburg | Mills | Larry | ย | 74,999 | ย |
COPY
๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ ๋ด๋ณด๋ด๊ธฐ
- ๋ฐ์ดํฐ๋ฅผ ๋ด๋ณด๋ผ ๋๋
FROM
์ ๋ก ๋ฐ์ดํฐ๋ฅผ ์๋ณํ๋ ๋์TO
๋ฅผ ์ฌ์ฉํ๋ค. - ์ ์ฒด ํ ์ด๋ธ์ ๋ด๋ณด๋ด๊ฑฐ๋ ๋จ ๋ช ๊ฐ์ ์ด๋ง ๋ด๋ณด๋ผ ์ ์๋ค.
- ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ธ๋ฐํ๊ฒ ์กฐ์ ํ์ฌ ๋ฐ์ดํฐ๋ฅผ ๋ด๋ณด๋ด๊ธฐ๋ ํ๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- COPY๋ก ์ ์ฒด ํ
์ด๋ธ ๋ด๋ณด๋ด๊ธฐ
COPY us_counties_pop_est_2019
TO 'C:\YourDirectory\us_counties_export.txt'
WITH (FORMAT CSV, HEADER, DELIMITER '|');
-- COPY๋ก ํ
์ด๋ธ์ ํน์ ์ด๋ง ๋ด๋ณด๋ด๊ธฐ
COPY us_counties_pop_est_2019
(county_name, internal_point_lat, internal_point_lon)
TO 'C:\YourDirectory\us_counties_latlon_export.txt'
WITH (FORMAT CSV, HEADER, DELIMITER '|');
-- COPY๋ฅผ ์ด์ฉํ ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ ๋ด๋ณด๋ด๊ธฐ
COPY (
SELECT county_name, state_name
FROM us_counties_pop_est_2019
WHERE county_name ILIKE '%mill%'
)
TO 'C:\YourDirectory\us_counties_mill_export.csv'
WITH (FORMAT CSV, HEADER);
- ๊ตฌ๋ถ ๊ธฐํธ๋ฅผ ์ผํ๋ก ํ์ง ์๋๋ค๋ฉด,
csv
ํ์ผ์ด ์๋txt
ํ์ผ๋ก ๋ด๋ณด๋ด๋ ๊ฒ์ด ์ข๋ค.
This post is licensed under CC BY 4.0 by the author.