Re: change "attnum <=0" to "attnum <0" for better reflect system attribute - Mailing list pgsql-hackers

From Tom Lane
Subject Re: change "attnum <=0" to "attnum <0" for better reflect system attribute
Date
Msg-id 3344596.1725939043@sss.pgh.pa.us
Whole thread Raw
In response to change "attnum <=0" to "attnum <0" for better reflect system attribute  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
jian he <jian.universality@gmail.com> writes:
> get_attnum says:
> Returns InvalidAttrNumber if the attr doesn't exist (or is dropped).

> So I conclude that "attnum == 0"  is not related to the idea of a system column.

attnum = 0 is also used for whole-row Vars.  This is a pretty
unfortunate choice given the alternative meaning of "invalid",
but cleaning it up would be a daunting task (with not a whole
lot of payoff in the end, AFAICS).  It's deeply embedded.

That being the case, you have to tread *very* carefully when
considering making changes like this.

> for example, ATExecColumnDefault, following code snippet,
> the second ereport should be "if (attnum < 0)"

>     /* Prevent them from altering a system attribute */
>     if (attnum <= 0)

I think that's just fine as-is.  Sure, the == case is unreachable,
but it is very very common to consider whole-row Vars as being more
like system attributes than user attributes.  In this particular
case, for sure we don't want to permit attaching a default to a
whole-row Var.  So I'm content to allow the duplicative rejection.

            regards, tom lane



pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: change "attnum <=0" to "attnum <0" for better reflect system attribute
Next
From: Thomas Munro
Date:
Subject: Re: Use streaming read API in ANALYZE