create table in postgreSQL

2019-03-08 03:13发布

I do not understand what is wrong with this query? Query tool does not want to create a table in 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)
);

4条回答
淡お忘
2楼-- · 2019-03-08 03:20
-- 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;
查看更多
甜甜的少女心
3楼-- · 2019-03-08 03:29

First the bigint(20) not null auto_increment will not work, simply use bigserial primary key. Then datetime is timestamp in PostgreSQL. All in all:

CREATE TABLE article (
    article_id bigserial primary key,
    article_name varchar(20) NOT NULL,
    article_desc text NOT NULL,
    date_added timestamp default NULL
);
查看更多
Anthone
4楼-- · 2019-03-08 03:32

Replace bigint(20) not null auto_increment by bigserial not null and datetime by timestamp

查看更多
别忘想泡老子
5楼-- · 2019-03-08 03:39

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)
);
查看更多
登录 后发表回答