2017-07-20 24 views
1

所以我目前正在为自己的一个项目工作,所以我可以学习如何使用postgresql和读取数据库日志。该项目的目标是创建一个数据库,检查关键词的网站,数据库将记录该网站找到或未找到该词的次数。每次发现该单词时,都会添加一个时间戳,告诉我该单词的发现时间和日期。到目前为止,我已经创建了我的数据库,但是我一直在创建表,我不知道如何将信息填入表中。我在unbuntu linux系统上构建这个postgresql。如何将信息导入Postgresql数据库并为其创建表?

+0

而Postgres教程[创建新表(https://www.postgresql.org/docs/current/static/tutorial-table.html) –

回答

0

用SQL创建表。

在Postgres的10和其他一些数据库,这将是:

CREATE TABLE word_found_ (
    id_ BIGINT       -- 64-bit number for virtually unlimited number of records. 
      GENERATED ALWAYS AS IDENTITY -- Generate sequential number by default. Tag as NOT NULL. 
      PRIMARY KEY ,     -- Create index to enforce UNIQUE. 
    when_ TIMESTAMP WITH TIME ZONE.  -- Store the moment adjusted into UTC. 
      DEFAULT CURRENT_TIMESTAMP , -- Get the moment when this current transaction began. 
    count_ INTEGER      -- The number of times the target word was found. 
) ; 

Postgres的10之前,使用SERIAL代替GENERATED ALWAYS AS IDENTITY。或者,在Stack Overflow中搜索有关使用UUID作为主键的信息,其中默认情况下由ossp-uuid扩展名生成值。

为每个采样插入一行。

INSERT INTO word_found_ (count_) 
VALUES (42) 
; 
相关问题