#18 PostgreSQL Extensions
#18.0 Introduction
Extention์ ํ์ฉํด ๊ธฐ์กด database๊ฐ ํ์ง ๋ชปํ๋ ๊ฒ๋ค์ ๊ฐ๋ฅํ๊ฒ ํด์ค โ postgreSQL ์ ๊ฐ์ฅ ํฐ ์ฅ์
select * from pg_available_extensions;
-- ํ์ฑํ / ๋นํ์ฑํ
CREATE EXTENSION hstore;
DROP EXTENSION hstore;
-- ์ฌ์ฉํ extension ํ์ธ
SELECT * FROM pg_extension;#18.1 HSTORE
CREATE TABLE users (
user_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
prefs HSTORE
);
INSERT INTO users (prefs) VALUES
('theme => dark, lang => kr, notifications => off'),
('theme => light, lang => es, notifications => on, push_notifications => on, email_notifications => off'),
('theme => dark, lang => it, start_page => dashboard, font_size => large');
SELECT * FROM USERS;
-- HSSTORE, JSON ํ์
์ ์ฌ์ฉํ๋ฉด ์ค์ฒฉ๋ ์ ๋ณด๋ฅผ ๊ฐ์ง ์ ์๋๋ฐ HSTORE๋ ์ด๋ฅผ ๋ฐฉ์งํจ
SELECT
user_id,
prefs -> 'theme',
prefs -> ARRAY['lang', 'notifications'],
prefs ? 'font_size' AS has_font_size,
prefs ?| ARRAY['push_notifications', 'start_page']
FROM users;
SELECT
user_id,
akeys(prefs),
avals(prefs)
FROM users;
SELECT
user_id,
each(prefs)
FROM users;
-- UPDATE
UPDATE users
SET
prefs['theme'] = 'light'
WHERE user_id = 1;
UPDATE users
SET
prefs = prefs || hstore(
ARRAY['currency', 'cookies_ok'],
ARRAY['krw', 'yes']
)
-- DELETE
UPDATE users
SET prefs = delete(prefs, 'cookies_ok');
SELECT * from users;
DROP TABLE users#18.2 PGCrypto
#18.3 UUID
Last updated
Was this helpful?