如何将以下查询转换为 postgresql

发布于 2024-12-12 03:30:06 字数 700 浏览 0 评论 0原文

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;

我实际上想知道一部分:

 PRIMARY KEY (sdate,deptID,opID)
Here the problem occurs because the

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;

I wonder in fact part :

 PRIMARY KEY (sdate,deptID,opID)

Here the problem occurs because the

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱倦旧时光 2024-12-19 03:30:06

一些问题:

  • 除非您使用 9.1 或更高版本,否则您不会有 IF NOT EXISTS
  • PostgreSQL 不知道 int(10) 的含义,您只需要 int
  • PostgreSQL 不知道 unsigned 是什么意思。
  • 用于引用标识符的反引号是 MySQLism,大多数数据库使用双引号(标准)。
  • 支持 smallint,但 int

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

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

A few issues:

  • You won't have IF NOT EXISTS unless you're using 9.1 or higher.
  • PostgreSQL doesn't know what int(10) means, you just want int.
  • PostgreSQL doesn't know what unsigned means.
  • Backticks for quoting identifiers is a MySQLism, most databases use double quotes (the standard).
  • smallint is supported but int is recommended unless you are tight on disk space.

So something like this should work:

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")
);

If you needed the extra space that an unsigned value would give you
then you could use bigint instead of int.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文