IF ROW( NEW ) <> ROW( OLD )

Started by Richard Broersmaalmost 18 years ago4 messagesgeneral
Jump to latest
#1Richard Broersma
richard.broersma@gmail.com

Is it possible to "cast" a table type to a ROW so that Row-Wise
comparison can be achieved?

--
Regards,
Richard Broersma Jr.

Visit the Los Angles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

#2Richard Broersma
richard.broersma@gmail.com
In reply to: Richard Broersma (#1)
Re: IF ROW( NEW ) <> ROW( OLD )

On Wed, Jun 25, 2008 at 4:40 PM, Joshua D. Drake <jd@commandprompt.com> wrote:

I have never tried it but you may be able to do it with a composite
type.

True. However, I was under the impression that table types were
essentially composite types. So I thought that composite types would
behave the same.

I could manually expand the composite type OLD and NEW to enumerate
each field and make a row wise comparison. However, I was hoping to
avoid that.
--
Regards,
Richard Broersma Jr.

Visit the Los Angles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Richard Broersma (#2)
Re: IF ROW( NEW ) <> ROW( OLD )

"Richard Broersma" <richard.broersma@gmail.com> writes:

I could manually expand the composite type OLD and NEW to enumerate
each field and make a row wise comparison. However, I was hoping to
avoid that.

I think IF ROW(NEW.*) <> ROW(OLD.*) will work in recent releases.

Actually you'd better use IF ROW(NEW.*) IS DISTINCT FROM ROW(OLD.*) ...
you really don't want to rely on <> as it will not give the behavior
you want in the presence of null columns.

regards, tom lane

#4Richard Broersma
richard.broersma@gmail.com
In reply to: Tom Lane (#3)
Re: IF ROW( NEW ) <> ROW( OLD )

On Wed, Jun 25, 2008 at 8:17 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I think IF ROW(NEW.*) <> ROW(OLD.*) will work in recent releases.

Actually you'd better use IF ROW(NEW.*) IS DISTINCT FROM ROW(OLD.*) ...
you really don't want to rely on <> as it will not give the behavior
you want in the presence of null columns.

Thanks that worked!

--
Regards,
Richard Broersma Jr.

Visit the Los Angles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug