在 postgreSQL 中创建表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9826833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:23:32  来源:igfitidea点击:

create table in postgreSQL

postgresqlcreate-table

提问by A.H.

I do not understand what is wrong with this query? Query tool does not want to create a table in PostgreSQL.

我不明白这个查询有什么问题?查询工具不想在 PostgreSQL 中创建表。

CREATE TABLE article (
article_id bigint(20) NOT NULL auto_increment,
article_name varchar(20) NOT NULL,
article_desc text NOT NULL,
date_added datetime default NULL,
PRIMARY KEY (article_id)
);

回答by A.H.

First the bigint(20) not null auto_incrementwill not work, simply use bigserial primary key. Then datetimeis timestampin PostgreSQL. All in all:

首先bigint(20) not null auto_increment不起作用,只需使用bigserial primary key. 然后datetimetimestamp在 PostgreSQL 中。总而言之:

CREATE TABLE article (
    article_id bigserial primary key,
    article_name varchar(20) NOT NULL,
    article_desc text NOT NULL,
    date_added timestamp default NULL
);

回答by kn3l

-- Table: "user"

-- DROP TABLE "user";

CREATE TABLE "user"
(
  id bigserial NOT NULL,
  name text NOT NULL,
  email character varying(20) NOT NULL,
  password text NOT NULL,
  CONSTRAINT user_pkey PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE "user"
  OWNER TO postgres;

回答by sega_sai

Replace bigint(20) not null auto_incrementby bigserial not nulland datetimeby timestamp

更换bigint(20) not null auto_incrementbigserial not null并且 datetime通过timestamp

回答by skay

Please try this:

请试试这个:

CREATE TABLE article (
  article_id bigint(20) NOT NULL serial,
  article_name varchar(20) NOT NULL,
  article_desc text NOT NULL,
  date_added datetime default NULL,
  PRIMARY KEY (article_id)
);