postgresql 中 COPY 的语法

发布于 2024-11-03 09:01:13 字数 1234 浏览 3 评论 0原文

可能的重复:
postgresql 中的 COPY 语法

INSERT INTO contacts_lists (contact_id, list_id)
          SELECT contact_id, 67544
          FROM plain_contacts
          WHERE TRUE
                AND is_print = TRUE  AND TRUE  AND (NOT EXISTS (select title_id from company_types_lists_titles where company_types_list_id = 55321) OR title_id in (select title_id from company_types_lists_titles where company_types_list_id = 55321))             AND company_type_id = 7
            AND country_id IN (select country_id from countries_lists WHERE list_id = 67544)
                  AND ((state_id IS NULL OR country_id NOT IN (231,39) OR state_id IN (SELECT state_id FROM lists_states WHERE list_id = 67544))
        OR zone_ids && ARRAY(SELECT zone_id FROM lists_zones WHERE list_id = 67544)
      )

            AND (NOT EXISTS (select award_id from company_types_lists_top_awards where company_types_list_id = 55321) OR top_award_ids && ARRAY(select award_id from company_types_lists_top_awards where company_types_list_id = 55321))

如何使用此查询的复制命令来减少时间?

Possible Duplicate:
syntax for COPY in postgresql

INSERT INTO contacts_lists (contact_id, list_id)
          SELECT contact_id, 67544
          FROM plain_contacts
          WHERE TRUE
                AND is_print = TRUE  AND TRUE  AND (NOT EXISTS (select title_id from company_types_lists_titles where company_types_list_id = 55321) OR title_id in (select title_id from company_types_lists_titles where company_types_list_id = 55321))             AND company_type_id = 7
            AND country_id IN (select country_id from countries_lists WHERE list_id = 67544)
                  AND ((state_id IS NULL OR country_id NOT IN (231,39) OR state_id IN (SELECT state_id FROM lists_states WHERE list_id = 67544))
        OR zone_ids && ARRAY(SELECT zone_id FROM lists_zones WHERE list_id = 67544)
      )

            AND (NOT EXISTS (select award_id from company_types_lists_top_awards where company_types_list_id = 55321) OR top_award_ids && ARRAY(select award_id from company_types_lists_top_awards where company_types_list_id = 55321))

How can i use copy command for this query to reduce time?

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

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

发布评论

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

评论(2

兔小萌 2024-11-10 09:01:13

COPY 用于在文件和表之间复制数据。 COPY TO 用于将表的内容复制到文件。

如果您可以快速创建表,则可以更快地使用create table contacts_lists as select...,但情况似乎并非如此。

COPY is used copy data between a file and a table. COPY TO is used to copy the contents of a table to a file.

If you could create the table on the fly if would by faster to use create table contacts_lists as select..., but that does not seem to be the case.

南…巷孤猫 2024-11-10 09:01:13

COPY 在文件和表之间复制数据。

使用COPY不会减少时间。

COPY copies data between files and tables.

You won't reduce time using COPY.

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