pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: How to set a value when NULL
2+ messages / 2 participants
[nested] [flat]
* Re: How to set a value when NULL
@ 2020-03-11 11:49 sivapostgres@yahoo.com <sivapostgres@yahoo.com>
0 siblings, 1 reply; 2+ messages in thread
From: sivapostgres@yahoo.com @ 2020-03-11 11:49 UTC (permalink / raw)
To: Postgresql General Group <pgsql-general@lists.postgresql.org>
Hello,Need to set a value of Zero when the field value is NULL in trigger function.
Tried with,NEW.fieldname = NULLIF(NEW.fieldname, 0)
in before insert/update trigger.
Looks like it's not working. I'm doing anything wrong.
Happiness AlwaysBKR Sivaprakash
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: How to set a value when NULL
@ 2020-03-11 13:45 David G. Johnston <david.g.johnston@gmail.com>
parent: sivapostgres@yahoo.com <sivapostgres@yahoo.com>
0 siblings, 0 replies; 2+ messages in thread
From: David G. Johnston @ 2020-03-11 13:45 UTC (permalink / raw)
To: sivapostgres@yahoo.com <sivapostgres@yahoo.com>; +Cc: Postgresql General Group <pgsql-general@lists.postgresql.org>
On Wednesday, March 11, 2020, sivapostgres@yahoo.com <sivapostgres@yahoo.com>
wrote:
> Hello,
> Need to set a value of Zero when the field value is NULL in trigger
> function.
>
> Tried with,
> NEW.fieldname = NULLIF(NEW.fieldname, 0)
>
> in before insert/update trigger.
>
> Looks like it's not working. I'm doing anything wrong
>
NULLIF does the inverse of what you want - you expression returns null if
fieldna,e has a value of 0.
COALESCE is what you want.
Coalesce(fieldname, 0) — returns the first, non-null argument.
David J.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-03-11 13:45 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 11:49 Re: How to set a value when NULL sivapostgres@yahoo.com <sivapostgres@yahoo.com>
2020-03-11 13:45 ` David G. Johnston <david.g.johnston@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