< postgresql>将数据从临时表插入带有JSON值的主表

发布于 2025-02-13 04:58:04 字数 561 浏览 0 评论 0原文

我正在使用PostgreSQL,并且正在尝试从临时表中插入主表中。

在临时表中,我有2列:MD5SUM(VARCHAR和NOT NULL)和值(JSON数据)。

我尝试了这些查询:

insert into main_table SELECT distinct * FROM temp ON CONFLICT (md5sum) DO NOTHING;

但是

insert into main_table(md5sum, values)
    select distinct md5sum, values
    from main_table
         where not exists (
            select md5sum, scores
            from temp
            where 
               temp.md5sum = main_table.md5sum);

我一直遇到此错误:无法识别JSON类型的相等性操作员。

如何解决此错误?

I am using postgresql and I am trying to insert into the main table from a temporary table.

In the temp table I have 2 columns: md5sum (varchar and not null) and values (json data).

I tried these queries:

insert into main_table SELECT distinct * FROM temp ON CONFLICT (md5sum) DO NOTHING;

and

insert into main_table(md5sum, values)
    select distinct md5sum, values
    from main_table
         where not exists (
            select md5sum, scores
            from temp
            where 
               temp.md5sum = main_table.md5sum);

But I keep getting this error: could not identify an equality operator for type json.

How to solve this error?

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

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

发布评论

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

评论(1

旧瑾黎汐 2025-02-20 04:58:04

您不能在JSON类型上做不同的事情。解决方法是将其扔给JSONB。如果以下对您有用,请尝试。

insert into main_table 
SELECT distinct md5sum, scores::jsonb 
FROM temp ON CONFLICT (md5sum) DO NOTHING;

You cannot do distinct on json type. The workaround is to cast it to jsonb. Try if the following works for you.

insert into main_table 
SELECT distinct md5sum, scores::jsonb 
FROM temp ON CONFLICT (md5sum) DO NOTHING;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文