Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[NOVICE] Explanation of pg_column_size

5 views
Skip to first unread message

Steve Baldwin

unread,
Aug 1, 2016, 5:47:29 PM8/1/16
to
Hi all,

Can someone please explain the following to me:

mse=# with l as (select 0.1::numeric as numlit) select pg_column_size(numlit) as sz_numlit, pg_column_size(0.1::numeric) as sz_expr from l;
 sz_numlit | sz_expr
-----------+---------
         5 |       8
(1 row)

It looks as though the expression is being cast to double precision, but maybe it is invalid to use pg_column_size in this way.

I'm using 9.5.3 on OS X.

Thanks,

Steve

Tom Lane

unread,
Aug 1, 2016, 6:13:30 PM8/1/16
to
Steve Baldwin <steve....@gmail.com> writes:
> Can someone please explain the following to me:

> mse=# with l as (select 0.1::numeric as numlit) select
> pg_column_size(numlit) as sz_numlit, pg_column_size(0.1::numeric) as
> sz_expr from l;
> sz_numlit | sz_expr
> -----------+---------
> 5 | 8
> (1 row)

I think the first case is putting the value into a tuple, which will cause
it to be trimmed to short-header form (1 length byte, 4 payload bytes).
In the other case you're looking at a raw numeric_in result, which will
be in the default 4-byte-length-word format (plus the same 4 payload
bytes). The former would be a more accurate representation of how
big this specific value would be on-disk.

regards, tom lane


--
Sent via pgsql-novice mailing list (pgsql-...@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

0 new messages