gpt4 book ai didi

sql - Postgresql:按顺序插入嵌套选择和 NEXTVAL

转载 作者:行者123 更新时间:2023-11-29 14:16:57 25 4
gpt4 key购买 nike

我已经寻找并没有找到这个问题的答案:

我使用嵌套选择插入一行,但还需要 uid 序列和日期戳

SQL 插入

 insert into countdegreejob   (countdegreeid,jobid,uniquejobid,  id, created, updated) 

select (cjtbdn.countdegreeid, j.id, j.uniquejobid ) NEXTVAL('hibernate_sequence'), now(), now()
from job j

right join job_areasofstudy jd on j.id = jd.job_id

inner join countjobtitlebydegreename cjtbdn on j.uniquejobid=cjtbdn.uniquejobid

where cjtbdn.degreename = jd.areasofstudy and jd.job_id is not NULL

我收到以下错误:

ERROR: syntax error at or near "(" LINE 2: ...jtbdn.countdegreeid, j.id, j.uniquejobid ) NEXTVAL('hibernat...

任何帮助将不胜感激

最佳答案

尝试删除括号并添加一个逗号:

select cjtbdn.countdegreeid, j.id, j.uniquejobid, NEXTVAL('hibernate_sequence'), now(), now()

当您将列括在括号中时,您是在告诉 Postgres 您需要一种记录格式。所以,这些是不一样的:

select 1, 2
select (1, 2)

第一个返回两列。第二个返回一列恰好是具有两个字段的记录。我怀疑您表格中的任何列实际上都是记录。

等等。该插入没有完全意义。您要插入 6 列,但 insert 列表中只有 5 列。你真正想做什么?

关于sql - Postgresql:按顺序插入嵌套选择和 NEXTVAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44749760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com