Can I use return value of INSERT…RETURNING in another INSERT?

前端 未结 6 1396
天涯浪人
天涯浪人 2020-12-02 09:05

Is something like this possible?

INSERT INTO Table2 (val)
VALUES ((INSERT INTO Table1 (name) VALUES (\'a_title\') RETURNING id));

like usin

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 09:09

    The best practice for this situation. Use RETURNING … INTO.

    INSERT INTO teams VALUES (...) RETURNING id INTO last_id;
    

    Note this is for PLPGSQL

提交回复
热议问题