【问题标题】:How to translate the following query to postgresql如何将以下查询转换为 postgresql
【发布时间】:2011-12-15 12:49:58
【问题描述】:
CREATE TABLE IF NOT EXISTS `p_reqstats` (
  `sdate` int(10) unsigned NOT NULL,
  `deptID` int(10) unsigned NOT NULL,
  `opID` int(10) unsigned NOT NULL,
  `requests` int(10) NOT NULL,
  `taken` smallint(5) unsigned NOT NULL,
  `declined` smallint(5) unsigned NOT NULL,
  `message` smallint(5) unsigned NOT NULL,
  `initiated` smallint(5) unsigned NOT NULL,
  `initiated_taken` smallint(5) unsigned NOT NULL,
  `rateit` smallint(5) unsigned NOT NULL,
  `ratings` smallint(5) unsigned NOT NULL,
  PRIMARY KEY (`sdate`,`deptID`,`opID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

我想知道其实部分:

 主键 (sdate,deptID,opID)
这里出现问题是因为

【问题讨论】:

  • 什么版本的postgresql?到目前为止你尝试了什么,你在哪里卡住了?

标签: mysql postgresql


【解决方案1】:

几个问题:

  • 除非您使用的是 9.1 或更高版本,否则您不会拥有 IF NOT EXISTS
  • PostgreSQL 不知道int(10) 是什么意思,你只需要int
  • PostgreSQL 不知道unsigned 是什么意思。
  • 引用标识符的反引号是 MySQL 主义,大多数数据库使用双引号(标准)。
  • smallint 受支持,但 int is recommended 除非您的磁盘空间紧张。

所以这样的事情应该可以工作:

create table "p_reqstats" (
    "sdate" int NOT NULL,
    "deptID" int NOT NULL,
    "opID" int NOT NULL,
    "requests" int NOT NULL,
    "taken" smallint NOT NULL,
    "declined" smallint NOT NULL,
    "message" smallint NOT NULL,
    "initiated" smallint NOT NULL,
    "initiated_taken" smallint NOT NULL,
    "rateit" smallint NOT NULL,
    "ratings" smallint NOT NULL,
    PRIMARY KEY ("sdate","deptID","opID")
);

如果你需要一个无符号值会给你的额外空间 那么你可以使用bigint 而不是int

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    相关资源
    最近更新 更多