0

I have sought and not found the answer to this problem:

I insert a row using nested select but also need the uid sequence and datestamp

SQL insert

 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 

I get the following error:

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

Any help would be much appreciated

2 Answers 2

2

Try removing the parentheses and adding a comma:

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

When you enclose columns in parentheses, you are telling Postgres that you want a record format. So, these are not the same:

select 1, 2
select (1, 2)

The first returns two columns. The second returns one column which happens to be a record with two fields. I doubt any of the columns in your tables are actually records.

Wait. That insert doesn't make full sense. You are inserting 6 columns but have only 5 in the insert list. What do you really want to do?

Sign up to request clarification or add additional context in comments.

1 Comment

that was a typo. there should be an "id" in there
1

You are missing a , before NEXTVAL as below

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

Also those parenthesis () in select are not required

1 Comment

Actually the parentheses are not only "not required", they are plain wrong. (cjtbdn.countdegreeid, j.id, j.uniquejobid) is a single column (a record with three fields). cjtbdn.countdegreeid, j.id, j.uniquejobid are three columns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.