Postgresql入门笔记:从基础到进阶
发表时间: 2023-07-13 16:01
CREATE TYPE rainbow AS ENUM ('红', '橙', '黄', '绿', '蓝', '靛', '紫');CREATE TABLE colors (id rainbow);
CREATE TABLE servers ( hostname text, ip inet);
CREATE TABLE reservations ( room int, during tsrange);INSERT INTO reservations VALUES (1108, '[2010-01-01 14:30, 2010-01-01 15:30)');
CREATE TYPE rainbow AS ENUM ('红', '橙', '黄', '绿', '蓝', '靛', '紫');CREATE TABLE colors ( id serial PRIMARY KEY, name rainbow);INSERT INTO colors (name) VALUES ('红'), ('橙'), ('黄');
CREATE TABLE servers ( id serial PRIMARY KEY, hostname text, ip inet);INSERT INTO servers (hostname, ip) VALUES ('server1', '192.168.0.100'), ('server2', '10.23.200.150');
SELECT id, COUNT(*) OVER() AS total FROM table;
CREATE TABLE users ( id SERIAL PRIMARY KEY, name text);
CREATE TABLE users ( ...) INHERITS (person);
CREATE TRIGGER ...;
CREATE FUNCTION myfunc() RETURNS void AS $BEGIN ...END;$ LANGUAGE plpgsql;
SELECT * FROM pg_stats WHERE tablename = 'mytable';
EXPLAIN SELECT * FROM mytable;