I need take the id of anexo an then the result id list insert in another table
with new_id as(INSERT INTO
clienteproveedor.anexo
(
codigo,
estado,
facturar,
observaciones,
servicioproductocontratadoid,
formaspagoid
)
select
ServiciosPorAnexo.CodAnexo,
ServiciosPorAnexo.cancelado,
serviciosporanexo.facturacion,
ServiciosPorAnexo.MotivosElim,
ServiciosPorAnexo.codigo_servicio,
ServiciosPorAnexo.FormaPago
from clienteproveedor.serviciosporanexo
returning id);
Yes you can do that, and you are close. Your problem being your
returning
clause is in the wrong place. Try:NOTE: Not tested as I do not have table definitions nor example data.