pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to manipulate field in New record
4+ messages / 3 participants
[nested] [flat]

* How to manipulate field in New record
@ 2023-06-07 12:12  Lorusso Domenico <domenico.l76@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Lorusso Domenico @ 2023-06-07 12:12 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hello,
Looking for a global solution I've write e trigger function that as
optional parameter (argv[0]) receive the name of a specific parameter.

My need is to get the filed from NEW and OLD record manipulate and set back
the field with new value.

Problem 1: how to get and set this field
Problem 2: the field has Composit type

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to manipulate field in New record
@ 2023-06-07 12:58  hubert depesz lubaczewski <depesz@depesz.com>
  parent: Lorusso Domenico <domenico.l76@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: hubert depesz lubaczewski @ 2023-06-07 12:58 UTC (permalink / raw)
  To: Lorusso Domenico <domenico.l76@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

On Wed, Jun 07, 2023 at 02:12:58PM +0200, Lorusso Domenico wrote:
> Hello,
> Looking for a global solution I've write e trigger function that as
> optional parameter (argv[0]) receive the name of a specific parameter.
> 
> My need is to get the filed from NEW and OLD record manipulate and set back
> the field with new value.
> 
> Problem 1: how to get and set this field
> Problem 2: the field has Composit type

Do this in pl/perl, pl/python, pl/tcl or anything like this.

Or use one of methods shown here:
https://www.depesz.com/2021/04/21/getting-value-from-dynamic-column-in-pl-pgsql-triggers/

depesz





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to manipulate field in New record
@ 2023-06-07 13:57  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Lorusso Domenico <domenico.l76@gmail.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Adrian Klaver @ 2023-06-07 13:57 UTC (permalink / raw)
  To: Lorusso Domenico <domenico.l76@gmail.com>; pgsql-general@lists.postgresql.org

On 6/7/23 05:12, Lorusso Domenico wrote:
> Hello,
> Looking for a global solution I've write e trigger function that as 
> optional parameter (argv[0]) receive the name of a specific parameter.
> 
> My need is to get the filed from NEW and OLD record manipulate and set 
> back the field with new value.

A new row won't have the OLD RECORD.

Read:

https://www.postgresql.org/docs/current/plpgsql-trigger.html

and look at the examples.

> 
> Problem 1: how to get and set this field
> Problem 2: the field has Composit type

-- 
Adrian Klaver
adrian.klaver@aklaver.com






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to manipulate field in New record
@ 2023-06-07 16:46  Lorusso Domenico <domenico.l76@gmail.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Lorusso Domenico @ 2023-06-07 16:46 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general@lists.postgresql.org

yes I know, the trigger should be before insert update and delete, and the
function decide what manipulate basing on TG_OP

Il giorno mer 7 giu 2023 alle ore 15:57 Adrian Klaver <
adrian.klaver@aklaver.com> ha scritto:

> On 6/7/23 05:12, Lorusso Domenico wrote:
> > Hello,
> > Looking for a global solution I've write e trigger function that as
> > optional parameter (argv[0]) receive the name of a specific parameter.
> >
> > My need is to get the filed from NEW and OLD record manipulate and set
> > back the field with new value.
>
> A new row won't have the OLD RECORD.
>
> Read:
>
> https://www.postgresql.org/docs/current/plpgsql-trigger.html
>
> and look at the examples.
>
> >
> > Problem 1: how to get and set this field
> > Problem 2: the field has Composit type
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
>

-- 
Domenico L.

per stupire mezz'ora basta un libro di storia,
io cercai di imparare la Treccani a memoria... [F.d.A.]

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2023-06-07 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 12:12 How to manipulate field in New record Lorusso Domenico <domenico.l76@gmail.com>
2023-06-07 12:58 ` hubert depesz lubaczewski <depesz@depesz.com>
2023-06-07 13:57 ` Adrian Klaver <adrian.klaver@aklaver.com>
2023-06-07 16:46   ` Lorusso Domenico <domenico.l76@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox