当我执行import foreign schema constructor from server mysql_svr into mysql_fdw;时,我得到:

ERROR:  type "set" does not exist
LINE 6:   type set NOT NULL,
               ^
QUERY:  CREATE FOREIGN TABLE search_requests (
  id int NOT NULL,
  ctime timestamp NOT NULL,
  site_id int NOT NULL,
  query_id int NOT NULL,
  type set NOT NULL,
  page smallint NOT NULL
) SERVER mysql_svr OPTIONS (dbname 'constructor', table_name 'search_requests');

CONTEXT:  importing foreign table "search_requests"


源表是:

CREATE TABLE `search_requests` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `site_id` int(11) NOT NULL,
  `query_id` int(10) unsigned NOT NULL,
  `type` set('content','catalog','gallery') NOT NULL,
  `page` tinyint(3) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `site` (`site_id`)
) ENGINE=InnoDB AUTO_INCREMENT=391 DEFAULT CHARSET=utf8


我可以获取由IMPORT FOREIGN SCHEMA生成的SQL进行的所有修复并手动运行吗?

最佳答案

API没有提及类似的内容(至少在SQL级别上),但是您可以import the schema without explicit tables。您可以尝试:

IMPORT FOREIGN SCHEMA constructor
  EXCEPT (search_requests)
  FROM SERVER mysql_svr
  INTO mysql_fdw


导入后,您可以尝试为每个排除的表f.ex.编写一个映射:

CREATE FOREIGN TABLE search_requests (
  id int NOT NULL,
  ctime timestamp NOT NULL,
  site_id int NOT NULL,
  query_id int NOT NULL,
  type text NOT NULL,
  page smallint NOT NULL
) SERVER mysql_svr OPTIONS (dbname 'constructor', table_name 'search_requests');


注意:我不确定text类型是否适合MySQL的set类型。在MySQL中,set通常意味着不良的规范化(例如PostgreSQL中的数组列类型),如果可以更改外部表,则应该这样做。

另外,这似乎是mysql_fdw错误;如果是这种情况,则应在其错误跟踪系统中进行报告。

关于mysql - 如何获取由IMPORT FOREIGN SCHEMA生成的SQL?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36792720/

10-13 04:31