我正在研究PostgreSQL版本8.4.20。由于工作问题和在其上运行的现有数据库,我无法升级它。
我创建了一个如下所示的模式:
--
-- Name: Bug Tracking; Type: COMMENT; Schema: bugtrackingdb; Owner: aa2_role
--
COMMENT ON DATABASE bugtrackingdb IS 'CCDD Viewer Web Application Bug Tracking DB.';
--- CREATE DATABASE bugtrackingdb;
CREATE SCHEMA bugtracking AUTHORIZATION aa2;
CREATE TABLE bugtracking.issues (
issueID BIGSERIAL PRIMARY KEY,
issue VARCHAR(50) NOT NULL
);
CREATE TABLE bugtracking.users (
id BIGSERIAL PRIMARY KEY,
issueID BIGINT NOT NULL UNIQUE REFERENCES bugtracking.issues(issueID),
userName VARCHAR(25) NOT NULL
);
CREATE TABLE bugtracking.openDate (
issueID BIGINT NOT NULL UNIQUE REFERENCES bugtracking.issues(issueID),
dateOpened DATE NOT NULL
);
CREATE TABLE bugtracking.closeDate (
issueID BIGINT NOT NULL UNIQUE REFERENCES bugtracking.issues(issueID),
dateClosed DATE NOT NULL
);
CREATE TABLE bugtracking.priority (
priorityID BIGSERIAL PRIMARY KEY,
issueID BIGINT NOT NULL UNIQUE REFERENCES bugtracking.issues(issueID),
priority VARCHAR(15) NOT NULL
);
CREATE TABLE bugtracking.status (
statusID BIGSERIAL PRIMARY KEY,
issueID BIGINT NOT NULL UNIQUE REFERENCES bugtracking.issues(issueID),
status VARCHAR(20) NOT NULL
);
CREATE TABLE bugtracking.comments (
commentID BIGSERIAL PRIMARY KEY,
issueID BIGINT NOT NULL UNIQUE REFERENCES bugtracking.issues(issueID),
description TEXT NOT NULL
);
我还是postgreSQL的新手,虽然我熟悉数据库是如何工作的,但我正在努力解决这个问题,我想知道我是否正确地做了这个。
我已经连接到数据库,并且我已经成功地创建了模式。
在数据库中创建SCHEMA后,psql返回了一系列通知,如:
bugtrackingdb.sql:14: NOTICE: CREATE TABLE will create implicit sequence "issues_issueid_seq" for serial column "issues.issueid"
bugtrackingdb.sql:14: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "issues_pkey" for table "issues"
CREATE TABLE
bugtrackingdb.sql:20: NOTICE: CREATE TABLE will create implicit sequence "users_id_seq" for serial column "users.id"
bugtrackingdb.sql:20: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "users_pkey" for table "users"
bugtrackingdb.sql:20: NOTICE: CREATE TABLE / UNIQUE will create implicit index "users_issueid_key" for table "users"
CREATE TABLE
我的问题是,当我运行psql命令\dt
来查看表列表时,我收到No relations found
消息。
但是,当我运行\dt *.
时,我得到:
List of relations
Schema | Name | Type | Owner
--------------------+-------------------------+-------+----------
bugtracking | closedate | table | aa2
bugtracking | comments | table | aa2
bugtracking | issues | table | aa2
bugtracking | opendate | table | aa2
bugtracking | priority | table | aa2
bugtracking | status | table | aa2
bugtracking | users | table | aa2
这是否意味着我已经成功创建了所有内容,现在我已准备好运行INSERT INTO命令和SELECT语句???
如果没有创建表格,那么我需要做些什么才能使其正常工作?
此外,我的SCHEMA是否正确编写或有更好的方法吗?
为什么我在运行No relations found
???
\dt
答案 0 :(得分:1)
这就是我创建数据模型的方法:
CREATE SCHEMA bugtracking AUTHORIZATION aa2;
CREATE TABLE bugtracking.issues (
issueID BIGSERIAL NOT NULL UNIQUE PRIMARY KEY,
issue VARCHAR(50) NOT NULL,
dateOpened DATE NOT NULL,
dateClosed DATE,
type VARCHAR(25) NOT NULL,
priority VARCHAR(15) NOT NULL,
status VARCHAR(20) NOT NULL,
comments TEXT NOT NULL
);
CREATE TABLE bugtracking.users (
id BIGSERIAL NOT NULL UNIQUE PRIMARY KEY,
issueID BIGINT NOT NULL UNIQUE REFERENCES bugtracking.issues(issueID),
userName VARCHAR(25) NOT NULL
);
这是我得到的输出。
bugtrackingdb=# INSERT INTO bugtracking.issues (issue, dateOpened, type, priority, status, comments) VALUES ('Test issue data', '20 Jul 2017', 'Logic Error', 'low', 'Not Started', 'Enter key needs to acctuate login button when pressed.');
INSERT 0 1
bugtrackingdb=# SELECT * FROM bugtracking.issues AS issueID; issueid | issue | dateopened | dateclosed | type | priority | status | comments
---------+-----------------+------------+------------+-------------+----------+-------------+--------------------------------------------------------
1 | Test issue data | 2017-07-20 | | Logic Error | low | Not Started | Enter key needs to acctuate login button when pressed.
(1 row)
考虑一下,一个用户将有许多问题需要报告,但每个问题只有每个列的一个实例。
只需2美分。你会用自己的方式自己写一百万个查询。