Re: semi-variable length type

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: James Harper <james(dot)harper(at)bendigoit(dot)com(dot)au>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: semi-variable length type
Date: 2014-02-21 06:09:51
Message-ID: 18671.1392962991@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

James Harper <james(dot)harper(at)bendigoit(dot)com(dot)au> writes:
> I want to make a float(n) type that emulates the mssql float type. The
> storage requirements are documented as 4 bytes for 1 <= n <=24, and 8
> bytes for 25 <= n <= 53.

Haven't we got that already?

regression=# create table t1 (f1 float(5), f2 float(30));
CREATE TABLE
regression=# \d t1
Table "public.t1"
Column | Type | Modifiers
--------+------------------+-----------
f1 | real |
f2 | double precision |

Other than the fact that we don't remember whether you asked for 5 bits
or 24, I think this meets the spec requirements.

> If I understand correctly, my options for
> emulating this in postgres are: 1. declare as variable length. Storage
> is then 8 bytes (4 byte length + 4 byte storage), or 12 bytes (4 byte
> length + 8 byte storage).

Well, you could use a short varlena header (1 byte). The type doesn't
need to be int-aligned, either, though whether that buys anything will
depend on context --- and you'll need to spend cycles realigning it,
if you want the code to work on non-Intel architectures.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message James Harper 2014-02-21 06:26:27 Re: semi-variable length type
Previous Message James Harper 2014-02-21 05:14:40 semi-variable length type