-4

I have a requirement to write a Postgres function to insert rows into one table from the other tables. But the problem is that only few columns needs to be set from the rows of the other table rest I need to set by myself.

In below table i just to fetch the youth_enrollment_id, youth_email from some other table rest column I will set as hard coded. I am trying something like below but it is not working

INSERT INTO moyadev.notification_email_details(
        id, youth_enrollment_id, youth_email, email_subject, email_body, 
        status, attempt, sent_date, last_updated_by, last_updated)
uuid_generate_v4(), 
SELECT id, email 
from moyadev.youth_enrollment, 
'subject', 'body', 'PENDING', '', '', 'SYSTEM', '2016-12-24 17:02:18.181'

and gives below error.

ERROR: syntax error at or near "uuid_generate_v4"
SQL state: 42601
Character: 205

Any help would be much appreciated. Thanks!

closed as off-topic by ypercubeᵀᴹ, mustaccio, Paul White Dec 28 '16 at 15:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – ypercubeᵀᴹ, mustaccio, Paul White
If this question can be reworded to fit the rules in the help center, please edit the question.

2

This is basic INSERT and SELECT syntax:

INSERT INTO moyadev.notification_email_details
       (id, youth_enrollment_id, youth_email, ..., last_updated)
SELECT uuid_generate_v4(), 
       ye.id, ye.email,
       'subject', 'body', 'PENDING', '', '', 
       'SYSTEM', '2016-12-24 17:02:18.181'
FROM moyadev.youth_enrollment AS ye ;

Not the answer you're looking for? Browse other questions tagged or ask your own question.