pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Keith Hankin <keith105@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: One byte integer support
Date: Thu, 6 Jan 2005 15:17:10 -0500 (EST)
Message-ID: <Pine.BSO.4.56.0501061508520.30558@leary.csoft.net> (raw)
In-Reply-To: <20050106181729.84477.qmail@web40625.mail.yahoo.com>
References: <20050106181729.84477.qmail@web40625.mail.yahoo.com>



On Thu, 6 Jan 2005, Keith Hankin wrote:

> Is there any way to support one byte integers? I am
> using JDBC and would like to use setByte() method to
> populate values of a single-byte integer valued
> column. I tried defining the column as character(1),
> but I get the error message:
> 
> Exception in thread "main"
> org.postgresql.util.PSQLException: ERROR: value too
> long for type character(1)
> 
> I don't see how a byte is too long for character(1).

Character is a textual data type, byte is a numeric value so when you set 
a byte value of say 145 to a text type you get the string '145' which is 
three characters.

Note that character(1) does not take up one byte of space on disk.  It is 
a one character field, not one byte.  Multibyte character sets may need 
more than one byte to store a single character, so this is variable byte 
length field that takes up at least 5 bytes of space.  4 bytes of length 
data and then the actual data bytes.

> Is there any data type like MySQL's tinyint?
> 

Possibly the system type "char" (needs the quotes), but I have no idea how 
that will work with the JDBC driver.  Going with smallint may be the best 
thing to do.  Before assuming that a tinyint would actually save you space 
you need to make sure you take into account padding and alignment.

Kris Jurka



view thread (6+ messages)  latest in thread

Message-ID: <Pine.BSO.4.56.0501061508520.30558@leary.csoft.net>
Permalink:  ../Pine.BSO.4.56.0501061508520.30558@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.56.0501061508520.30558@leary.csoft.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: books@ejurka.com, keith105@yahoo.com
  Subject: Re: One byte integer support
  In-Reply-To: <Pine.BSO.4.56.0501061508520.30558@leary.csoft.net>
  References: <20050106181729.84477.qmail@web40625.mail.yahoo.com> <Pine.BSO.4.56.0501061508520.30558@leary.csoft.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox