postgresql使用教程

在这里插入图片描述

Database

-- create database
CREATE DATABASE [database_name];
-- delete databse
DROP DATABASE [database_name];

Table

Create Table

create table [table_name](
	in int,
	name varchar(10),
)

Load data from & to database

-- Load data to Database
copy [table_name] from '/path/to/data/[data_name].csv' with DELIMITER AS E'\t';
-- Load data from Database
copy [table_name] to '/path/to/data/[data_name].csv' DELIMITER ',' CSV HEADER;

Explore table

-- see column name of table
select column_name from information_schema.columns where table_name='[table_name]';
-- see cardinality of a table satisfy predicates
select count(*) from [table_name] where [predicate];
-- get 10 random tuples from table
select * from [table_name] order by random() limit 10;
-- get 10 top tuples from table
select * from [table_name] limit 10; 

Role

-- see all roles
\du 
-- see what role are you and what database are you in
\c
-- create new role
create role [new_user];
-- set password for role
alter role [new_user] with password [your password];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值