笔记: 环境 - Postgre从安装到使用

711 阅读1分钟

Postgre基本使用

  • 安装

    利用homebrew安装 brew install postgresql

  • 启动

    利用命令行pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

    注意,postgrel默认启动端口为:5432,如果想要修改的话,就在后面加参数-p[port]

  • 基本命令

    • 进入环境 psql
    • 切换数据库 \c databasename
    • 显示数据表结构 \d tablename
    • 设置自增列 columnname SERIAL
    • 查看当前时区 show time zone
    • 新增表
      create table "xxxx" (
         "id" bigint SERIAL,
        "column1" timestamp without time zone NOT NULL
      );
      
    • 查询 select * from tablename
    • 新增 insert into tablename(column1) values(value1)
    • 删除 delete from tablename where condition
    • 更新 update tablename set column1 = value1 where condition
    • 格式化表数据 turncate tablename ...