关于oushudb-hawq:OushuDB-基本用法-创建数据库和表

5次阅读

共计 1090 个字符,预计需要花费 3 分钟才能阅读完成。


本节通过应用 OushuDB 的命令行工具 psql 来阐明如何创立根本数据库对象:database 和 table。因为 OushuDB 和 PostgreSQL 兼容,所以应用 OushuDB 的形式和应用 PostgresSQL 的形式基本相同,如果 OushuDB 的文档有些中央阐明不分明的话,用户也能够通过查阅 PostgresSQL 的帮忙文档来理解更多对于 OushuDB 的信息。

上面这条命令应用 psql 连贯 OushuDB 缺省装置的数据库 postgres,而后创立一个新的数据库 test,并在新的数据库中创立一个表 foo。

 changlei:build ChangLei$ psql -d postgres
 psql (8.2.15)
 Type "help" for help.

 postgres=# create database test;  # 创立数据库 test
 CREATE DATABASE

 postgres=# \c test  # 连贯进入 test 数据库
 You are now connected to database "test" as user "ChangLei".

 test=# create table foo(id int, name varchar);  # 创立表 foo
 CREATE TABLE

 test=# \d  # 显示以后数据库 test 中所有表
            List of relations
 Schema | Name | Type  |  Owner   |   Storage
--------+------+-------+----------+-------------
 public | foo  | table | ChangLei | append only
 (1 row)


 test=# insert into foo values(1, 'hawq'),(2, 'hdfs');
 INSERT 0 2

 test=# select * from foo; # 从表 foo 中抉择数据
  id | name
 ----+------
   1 | hawq
   2 | hdfs
 (2 rows)

 如果想删除表或者数据库的话能够应用 drop 语句。test=# drop table foo;
 DROP TABLE

 test=# \d
 No relations found.

 test=# drop database test;  # 因为当初在 test 数据库中,所以不能删除
 ERROR:  cannot drop the currently open database

 test=# \c postgres  # 首先连贯到 postgres 数据库,而后删除 test 数据库
 You are now connected to database "postgres" as user "ChangLei".

 postgres=# drop database test;
 DROP DATABASE
正文完
 0