简体   繁体   English

PostgreSQL JDBC-可以删除但不能重新创建索引

[英]PostgreSQL JDBC - can drop but not recreate indexes

I've been searching for an answer, but no luck so far... 我一直在寻找答案,但到目前为止没有运气...

I want to perform bulk operations on a database with potentially millions of records, reading the PostgreSQL guide: '13.4 Populating a Database' 1 , it suggests removing indexes and foreign-key constraints to speed up the copy operation. 我想对可能包含数百万条记录的数据库执行批量操作,请阅读PostgreSQL指南:“ 13.4填充数据库” 1 ,它建议删除索引和外键约束以加快复制操作。

I'm trying to accomplish this using JDBC statements, I'm finding that I can drop the indexes without any issue, but recreating them after populating the database has problems. 我正在尝试使用JDBC语句来完成此任务,发现可以删除索引没有任何问题,但是在填充数据库后重新创建它们有问题。 I get a syntax error 'at or near' the name of the index that I am creating: 我在创建的索引名称“或附近”出现语法错误:

Statement stmt = connection.createStatement();
String query = "CREATE UNIQUE INDEX type_uk ON cell (field1, field2, field3, field4) WHERE field3 AND field4 IS NOT NULL TABLESPACE lcindex";

stmt.executeUpdate(query);
connection.commit();

If I execute this query in psql, it successfully creates the index though, so I'm a bit confused... 如果我在psql中执行此查询,尽管它成功创建了索引,所以我有点困惑...

Any help, insights, suggestions, etc. would be much appreciated :) Thanks in advance. 任何帮助,见解,建议等,将不胜感激:)在此先感谢。

Can't comment on the answer like Michal Niklas did, but your sql statement is illegal in postgres and cannot work. 无法像Michal Niklas一样对答案发表评论,但是您的sql语句在postgres中是非法的,无法正常工作。 My guess: 我猜:

CREATE UNIQUE INDEX type_uk ON cell (field1, field2, field3, field4) TABLESPACE lcindex 
  where field3 is not null and field4 is not null;
  • tablespace should come before where 表空间应该放在哪里
  • every field in there where clause has to have "is not null" where子句中必须具有“不为空”的每个字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM