attnum.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*-------------------------------------------------------------------------
  2. *
  3. * attnum.h
  4. * POSTGRES attribute number definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/access/attnum.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef ATTNUM_H
  15. #define ATTNUM_H
  16. /*
  17. * user defined attribute numbers start at 1. -ay 2/95
  18. */
  19. typedef int16 AttrNumber;
  20. #define InvalidAttrNumber 0
  21. #define MaxAttrNumber 32767
  22. /* ----------------
  23. * support macros
  24. * ----------------
  25. */
  26. /*
  27. * AttributeNumberIsValid
  28. * True iff the attribute number is valid.
  29. */
  30. #define AttributeNumberIsValid(attributeNumber) \
  31. ((bool) ((attributeNumber) != InvalidAttrNumber))
  32. /*
  33. * AttrNumberIsForUserDefinedAttr
  34. * True iff the attribute number corresponds to a user defined attribute.
  35. */
  36. #define AttrNumberIsForUserDefinedAttr(attributeNumber) \
  37. ((bool) ((attributeNumber) > 0))
  38. /*
  39. * AttrNumberGetAttrOffset
  40. * Returns the attribute offset for an attribute number.
  41. *
  42. * Note:
  43. * Assumes the attribute number is for a user defined attribute.
  44. */
  45. #define AttrNumberGetAttrOffset(attNum) \
  46. ( \
  47. AssertMacro(AttrNumberIsForUserDefinedAttr(attNum)), \
  48. ((attNum) - 1) \
  49. )
  50. /*
  51. * AttrOffsetGetAttrNumber
  52. * Returns the attribute number for an attribute offset.
  53. */
  54. #define AttrOffsetGetAttrNumber(attributeOffset) \
  55. ((AttrNumber) (1 + (attributeOffset)))
  56. #endif /* ATTNUM_H */