Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20211124] PostgreSQL 기초 쿼리 #231

Open
JuHyun419 opened this issue Nov 24, 2021 · 0 comments
Open

[20211124] PostgreSQL 기초 쿼리 #231

JuHyun419 opened this issue Nov 24, 2021 · 0 comments
Labels

Comments

@JuHyun419
Copy link
Owner

PostgreSQL 문법 정리(pgAdmin 4 기반)

-- 전체 데이터베이스 조회
SELECT datname FROM pg_database;


-- 사용자가 생성한 데이터베이스만 조회(아래 두 개 동일)
SELECT datname FROM pg_database WHERE datistemplate = false;
SELECT * FROM pg_tables WHERE schemaname = 'public';


-- 전체 테이블 조회(show tables)
SELECT tablename FROM pg_tables;


-- 사용자가 생성한 테이블만 조회(아래 두 개 동일)
SELECT * FROM pg_tables WHERE schemaname = 'public';
SELECT RELNAME AS TABLE_NAME FROM PG_STAT_USER_TABLES;


-- 컬럼 목록 조회(desc table명)
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_CATALOG = 'yapp' AND TABLE_NAME = 'folder'
ORDER BY ORDINAL_POSITION;

SELECT *
FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'folder'
ORDER BY ordinal_position;


-- 컬럼 디폴트값 설정
ALTER TABLE folder ALTER COLUMN bookmark_count SET DEFAULT 0;
ALTER TABLE folder ALTER COLUMN created_at SET DEFAULT now();


-- id sequence(auto_increment) reset
ALTER SEQUENCE folder_id_seq RESTART WITH 7;
@JuHyun419 JuHyun419 changed the title [20211124] PostgreSQL 문법 정리 [20211124] PostgreSQL 기초 쿼리 Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant