zoukankan      html  css  js  c++  java
  • postgres 基础SQL语句 增删改

    查看已创建的数据库:select datname from pg_database;

    查看所有数据库的详细信息:select * from pg_database

    创建数据库:create database wzxdb

    删除数据库:drop database wzxdb;

    查看已创建的用户:select usename from  pg_user;

    创建用户并且指定密码:create user wzx with password '123456'

    删除用户:drop user wzx;

    修改用户密码:alter user wzx with password 'wzx123456'
    创建数据库并且指定用户:create database wzx with encoding='utf8' owner='wzx'

    查看已创建的表:select tablename from pa_tables;

    查看所有表的详细信息:select * from information_schema.tables where table_schema='public'

    查看当前数据库的所有表:select * from pg_tables where schemaname = 'public';

    创建表结构1:create table wzxstu1(
    id int ,
    name varchar(10) not Null,
    sex varchar(4) ,
    age int ,
    height float,
    registration_time date
    );
    创建表结构2:create table wzxstu (
    name varchar(80), -- 姓名
    age int, -- 年龄
    height int, -- 身高
    resg date -- 注册时间
    );

    删除表:drop table wzxstu;

    删除数据:delete from wzxstu;

    插入数据:INSERT INTO wzxstu1 VALUES (1,'San', '男', 50, 0.25, '2019-02-02');

    删除数据:delete from wzxstu1 where name like 'wzx%';
    更新数据:update wzxstu1 set name='你好的号' where name ='aa'

    查询数据:

    :select * from wzxstu;
    :select count(*) from wzxstu;
    :select max(age),min(age),count(*) from wzxstu;
    :select * from wzxstu order by age ;
    :select name from wzxstu group by name order by age;
    :select count(*) from kv2;
    :select * from kv2 where k like 'ss%';
    :select count(v) from kv2 group by v having count(v) >1;
    :select count(v) as a from kv2 group by v having a>1
    :select distinct name from wzxstu
    :select id from wzxstu order by id desc
    :select age from wzx order by age desc
    :select * from wzxstu limit 1
    :select sex,count(*) from wzxstu1 group by sex

    查看当前版本信息:select version();

    查看当前搜索路径:show search_path;

    添加新的模式到搜索路径:set  search_path TO myschema,public;

    二、示例

    select operate_time::timestamp + (extract(epoch FROM (now() - '2020-12-29 11:10:00'::timestamp )) || 'minute')::interval as operate_time from wzx212

    select id,operate_time::timestamp + (extract(epoch FROM (now() - CURRENT_DATE ))+ 7*3600 || 'minute')::interval as operate_time from wzx212 where operate_time::timestamp + (extract(epoch FROM (now() - CURRENT_DATE ))+ 7*3600 || 'minute')::interval <=now()

  • 相关阅读:
    [College] C++字符串读入与进制转化-关于《实践教程》P10[程序]的一些总结
    [College] 二进制与机器数的几种形式
    [College] Hello World!
    [SinGuLaRiTy] 复习模板-数学
    ByteCTF 2020 KOP Writeup
    【题解】电子科技大学第十八届 ACM 程序设计竞赛
    【逆向】某 VR 驱动分析过程
    物联网框架 IoTivity 中间人攻击分析
    批处理工具 CAPI 逆向分析之 API Call
    DASCTF 2020 六月赛 Reverse Writeup
  • 原文地址:https://www.cnblogs.com/wzx1blog/p/12758840.html
Copyright © 2011-2022 走看看