Skip to content
Advertisement

Select in return for postgres query

is it possible to add a select in a return statement?

insert into user_skills_languages 
(
  user_id, 
  skill_id,
  skill_type_id
)
values(
  213,
  1,
  0
)
returning skill_id, skill_type_id, select name from skills where skill_id = 1

I tried adding the select name from skills where skill_id = 1 but not sure if this is possible or I just don’t have the syntax right.

Advertisement

Answer

Yes, that is possible, but you have to enclose a subquery in parentheses:

RETURNING skill_id,
          skill_type_id,
          (SELECT name FROM skills WHERE skill_id = 1)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement