Hola como están quisiera ver si alguien me puede ayudar con un trigger en postgres , lo que pasa es que yo se como hacerlo en sql server y pensé que era algo similar pero creo que no lo es , dejo mi consulta que me arroja errores de que esta mal escrita.
Ya probé los select y los insert y si funcionan bien lo único que no estoy seguro es que si en postgres utilizo el inserted al momento del trigger y también cual es la estructura que tendría con este ejemplo, porfa si alguien me ayudara estaría super agradecido.
CREATE TRIGGER reten_account AFTER insert ON retenciones_ventas
[
BEGIN
insert into account_move(name ,date , ref ,state,
type,to_check,journal_id,company_id,partner_id,
commercial_partner_id,amount_total,auto_post,invoice_date,invoice_partner_display_name,
create_uid,create_date,write_date,write_uid,extract_state,
numero_documento,"type_documentId",currency_id)
(select inserted."nameSeq",CURRENT_DATE,'','posted',
'in_invoice','false',inserted.journal_id,account_move.company_id
,inserted.partner_id,inserted.partner_id,'0.00','false',
inserted.date_ret,account_move.invoice_partner_display_name,
inserted.create_uid,inserted.create_date,inserted.write_date,
inserted.write_uid,account_move.extract_state
,inserted.numero_retencion,inserted."type_documentId",account_move.currency_id
from inserted
inner join account_move on account_move.id = inserted.invoice_id)
insert into
account_move_line(move_id,move_name,date,journal_id,company_id,company_currency_id,
account_id,account_internal_type,
name,quantity,price_unit,debit,credit,balance,price_total,partner_id,create_date,create_uid,
write_uid,write_date)
(select lines.customerorder_id,inserted."nameSeq",CURRENT_DATE,
inserted.journal_id,account_move.company_id,
account_move.currency_id,lines.account_id,'other',inserted."nameSeq",'1',0-
(lines.total*-1),'0',lines.total *-1,0-(lines.total*-1),0-
(lines.total*-1),account_move.partner_id,inserted.create_date,inserted.create_uid,
inserted.write_uid,inserted.write_date
from inserted
inner join retenciones_ventas_retenciones_ventas_lines as lines on lines.customerorder_id =
inserted.id
inner join account_move on account_move.id = inserted.invoice_id)
insert into
account_move_line(move_id,move_name,date,journal_id,company_id,company_currency_id,
account_id,account_internal_type,
name,quantity,price_unit,debit,credit,balance,price_total,partner_id,create_date,create_uid,
write_uid,write_date)
(select lines.customerorder_id,inserted."nameSeq",CURRENT_DATE,inserted.journal_id,
account_move.company_id,
account_move.currency_id,lines.account_id,'other',inserted."nameSeq",'1',
(lines.total*-1)-0,lines.total *-1,'0'
,(lines.total*-1)-0,(lines.total*-1)-0,account_move.partner_id,inserted.create_date,
'inserted.create_uid,
inserted.write_uid,inserted.write_date
from inserted
inner join retenciones_ventas_retenciones_ventas_lines as lines on lines.customerorder_id =
inserted.id
inner join account_move on account_move.id = inserted.invoice_id)
update account_move set amount_total = (select sum(lines.total)*-1
from inserted
inner join retenciones_ventas_retenciones_ventas_lines as lines on lines.customerorder_id =
inserted.id
inner join account_move on account_move.id = inserted.invoice_id) where id =(select
invoice_id
from inserted
inner join retenciones_ventas_retenciones_ventas_lines as lines on lines.customerorder_id =
inserted.id
inner join account_move on account_move.id = inserted.invoice_id)
END;
];