postgresql

文档

https://www.postgresql.org/docs/14/tutorial-sql.html

安装

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

sudo yum install -y postgresql15-server

sudo /usr/pgsql-15/bin/postgresql-15-setup initdb

sudo systemctl enable postgresql-15

sudo systemctl start postgresql-15

修改密码

sudo passwd -d postgres

sudo -u postgres passwd

使用

启用客户端

sudo su postgres

创建数据库

psql createdb mydb

删除数据库

psql dropdb mydb

进入数据库

psql mydb

退出数据库

\q

创建数据库

CREATE TABLE weather (

city varchar(80),

temp_lo int, -- low temperature

temp_hi int, -- high temperature

prcp real, -- precipitation

date date

);

删除表

DROP TABLE weather;

写入数据

INSERT INTO weather (city, temp_lo, temp_hi, prcp, date)VALUES ('San Francisco', 43, 57, 0.0, '1994-11-29');

查询数据

SELECT * FROM weather;

修改

UPDATE weather SET temp_hi = temp_hi - 2, temp_lo = temp_lo - 2 WHERE date > '1994-11-28';

删除

DELETE FROM weather WHERE city = 'Hayward';

事务

BEGIN;

UPDATE accounts SET balance = balance - 100.00

WHERE name = 'Alice';

-- etc etc

COMMIT;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值