Skip site navigation (1) Skip section navigation (2)

Re: 1-byte integers

From: Greg Stark <gsstark(at)mit(dot)edu>
To: stig erikson <stigerikson_nospam_(at)yahoo(dot)se>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: 1-byte integers
Date: 2004-09-18 15:39:01
Message-ID: 87oek3mvsa.fsf@stark.xeocode.com (view raw or flat)
Thread:
Lists: pgsql-sql
stig erikson <stigerikson_nospam_(at)yahoo(dot)se> writes:

> how can i specify an integer to be one byte byte or even 4 bits long?
> int1, int(1), tinyint are nowhere to be seen.
> smallest i can find is smallint that is 2 bytes.

There's a type called "char" (the double quotes are needed). It's used by
postgres system catalogues but it's available for users too. It's a little
quirky since it has operators that treat it as a 1 byte text data type and
other operators that treat it as an integer data type. But that doesn't
normally lead to any problems, just strange symptoms when your code has a bug.

Other than that there are things like bit(4) which has a cast to and from
integer. But they won't save you any storage space. If you have multiple
columns like this and want to define a new type that aggregates them all for
storage but lets you access them individually that could be useful.

-- 
greg


In response to

pgsql-sql by date

Next:From: Tom LaneDate: 2004-09-18 16:39:21
Subject: Re: Sequence of SQL command execution involving triggers and stored procedures.
Previous:From: Omkar RathDate: 2004-09-18 04:54:24
Subject: Sequence of SQL command execution involving triggers and stored procedures.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group