用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)
;
而Postgres教程[創建新表(https://www.postgresql.org/docs/current/static/tutorial-table.html) –