postgresql操作

前端之家收集整理的这篇文章主要介绍了postgresql操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。



显示数据库
postgres=# select datname from pg_database;
datname
-----------
postgres
template1
template0
(3 行记录)

创建数据库
postgres=# create database core_dev;
CREATE DATABASE

postgres=# select datname from pg_database;
datname
-----------
postgres
core_dev
template1
template0
(4 行记录)

显示所有表相当于MysqL的showtables;
postgres=# SELECT table_name FROM information_schema.tables WHERE table_schema =
'public';
table_name
------------
(0 行记录)


创建表
postgres=# CREATE TABLE user_tbl(name VARCHAR(20),signup_date DATE);
CREATE TABLE
postgres=# SELECT table_name FROM information_schema.tables WHERE table_schema =
'public';
table_name
------------
user_tbl
(1 行记录)


插入数据
postgres=# INSERT INTO user_tbl(name,signup_date) VALUES('测试','2017-12-04')
;
INSERT 0 1

查询数据
postgres=# select * from user_tbl;
name | signup_date
------+-------------
测试 | 2017-12-04
(1 行记录)

显示表结构相当与MysqL的describetable_name;

postgres=# SELECT table_catalog,table_schema,table_name,column_name,udt_name FROM information_schema.columns WHERE table_name ='user_tbl'; table_catalog | table_schema | table_name | column_name | udt_name ---------------+--------------+------------+-------------+---------- postgres | public | user_tbl | name | varchar postgres | public | user_tbl | signup_date | date (2 行记录) postgres=#

原文链接:https://www.f2er.com/postgresql/193368.html

猜你在找的Postgre SQL相关文章