Skip to content

Instantly share code, notes, and snippets.

@handuy handuy/2.sql
Last active Sep 16, 2018

Embed
What would you like to do?
Cú pháp chạy: psql -U postgres -f [tên_file]. Chạy file 2.sql ở citus_master, 2_test.sql ở citus_worker_1
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS posts;
DROP SCHEMA IF EXISTS course CASCADE;
CREATE SCHEMA course;
CREATE TABLE users (id int, name text, age int);
CREATE TABLE posts (id int, title text);
CREATE TABLE course.lessons (id int, title text, point int);
SELECT create_reference_table('users');
SELECT create_reference_table('posts');
SELECT create_reference_table('course.lessons');
INSERT INTO users VALUES (1, 'Duy', 26), (2, 'Long', 24), (3, 'Huy', 28);
INSERT INTO posts VALUES (1, 'Hello World'), (2, 'Hello Citus'), (3, 'Hello Vietnam');
INSERT INTO course.lessons VALUES (1, 'Java', 10), (2, 'HTML', 20), (3, 'CSS', 40);
UPDATE users SET name = 'Cuong' WHERE id = 3;
DELETE FROM posts WHERE id = 3;
UPDATE course.lessons SET title = 'Javascript' WHERE id = 1;
SELECT * FROM users;
SELECT * FROM posts;
SELECT * FROM course.lessons;
\d
SELECT * FROM posts_102011;
SELECT * FROM users_102010;
select * from course.lessons_102021;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.