> I think "the value of S" implies "the user-accessible representation of
> the value of S", in the sense, "How much memory do I need to allocate to
> store this value".
>
> Furthermore, the size of the TOAST representation that is returned now is
> just one particular of several intermediate representations. For
> instance, it does not include the VARHDRSZ and it does not include the
> size of the tuple headers when it's stored externally. Thus, this size is
> heavily skewed toward low numbers and doesn't tell you much about either
> the disk end or the user's end.
Yes, good arguments. If we want to implement storage_length at some
later time, I think the compressed length may be appropriate, but for
general use, I think we need to return the uncompressed length,
especially considering that multibyte makes the ordinary 2length return
number of characters, so users need a way to get byte length.
Attached is a patch that makes text return the same value type as char()
and varchar() already do. As Tatsuo pointed out, they were
inconsistent. All the other octet_length() functions look fine so it
was only text that had this problem.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Index: src/backend/utils/adt/varlena.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v
retrieving revision 1.74
diff -c -r1.74 varlena.c
*** src/backend/utils/adt/varlena.c 2001/10/25 05:49:46 1.74
--- src/backend/utils/adt/varlena.c 2001/11/18 19:11:52
***************
*** 273,284 ****
Datum
textoctetlen(PG_FUNCTION_ARGS)
{
! struct varattrib *t = (struct varattrib *) PG_GETARG_RAW_VARLENA_P(0);
! if (!VARATT_IS_EXTERNAL(t))
! PG_RETURN_INT32(VARATT_SIZE(t) - VARHDRSZ);
!
! PG_RETURN_INT32(t->va_content.va_external.va_extsize);
}
/*
--- 273,281 ----
Datum
textoctetlen(PG_FUNCTION_ARGS)
{
! text *arg = PG_GETARG_VARCHAR_P(0);
! PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
}
/*