dbTalk Databases Forums  

One-byte integral type?

comp.databases.postgresql comp.databases.postgresql


Discuss One-byte integral type? in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Karsten Wutzke
 
Posts: n/a

Default One-byte integral type? - 09-05-2009 , 12:38 PM






Hello,

I see PostgreSQL doesn't have a real one-byte integral type, like
TINYINT. What do you use instead?

Karsten

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: One-byte integral type? - 09-07-2009 , 03:38 AM






Karsten Wutzke wrote:
Quote:
I see PostgreSQL doesn't have a real one-byte integral type, like
TINYINT. What do you use instead?
That's right.
You could use "smallint" instead which only uses 2 bytes.
If you want to prevent larger values to be inserted,
you could use a check constraint.

Yours,
Laurenz Albe

Reply With Quote
  #3  
Old   
Karsten Wutzke
 
Posts: n/a

Default Re: One-byte integral type? - 09-07-2009 , 06:06 AM



On 7 Sep., 10:38, "Laurenz Albe" <inv... (AT) spam (DOT) to.invalid> wrote:
Quote:
Karsten Wutzke wrote:
I see PostgreSQL doesn't have a real one-byte integral type, like
TINYINT. What do you use instead?

That's right.
You could use "smallint" instead which only uses 2 bytes.
If you want to prevent larger values to be inserted,
you could use a check constraint.

Yours,
Laurenz Albe
How do you ensure that a one-byte range type only occupies one byte?

Is it because of the SQL standard, that PostgreSQL doesn't have a one-
byte type, too?

Generally, I get the feeling the mainstream DBMS' around (PostgreSQL,
MySQL, Oracle, ...) don't like byte-wise types. Could it have to do
with two-byte memory alignment issues?

Karsten

Reply With Quote
  #4  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: One-byte integral type? - 09-07-2009 , 06:58 AM



Karsten Wutzke, 07.09.2009 13:06:
Quote:
Generally, I get the feeling the mainstream DBMS' around (PostgreSQL,
MySQL, Oracle, ...) don't like byte-wise types. Could it have to do
with two-byte memory alignment issues?
What's the use for a single-byte datatype? Space consideration should not matter nowadays.

If you want to make sure the values are limited to a certain numeric range, then use a check constraint.

Thomas

Reply With Quote
  #5  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: One-byte integral type? - 09-07-2009 , 09:37 AM



Karsten Wutzke wrote:
Quote:
I see PostgreSQL doesn't have a real one-byte integral type, like
TINYINT. What do you use instead?

That's right.
You could use "smallint" instead which only uses 2 bytes.
If you want to prevent larger values to be inserted,
you could use a check constraint.

How do you ensure that a one-byte range type only occupies one byte?
If you use a smallint, it will use two bytes.

Quote:
Is it because of the SQL standard, that PostgreSQL doesn't have a one-
byte type, too?
I didn't check, but I don't think so. That would be surprising.

Quote:
Generally, I get the feeling the mainstream DBMS' around (PostgreSQL,
MySQL, Oracle, ...) don't like byte-wise types. Could it have to do
with two-byte memory alignment issues?
Maybe, but I guess that there is no hige demand for it.

Yours,
Laurenz Albe

Reply With Quote
  #6  
Old   
Karsten Wutzke
 
Posts: n/a

Default Re: One-byte integral type? - 09-07-2009 , 11:16 AM



On 7 Sep., 16:37, "Laurenz Albe" <inv... (AT) spam (DOT) to.invalid> wrote:
Quote:
Karsten Wutzke wrote:
I see PostgreSQL doesn't have a real one-byte integral type, like
TINYINT. What do you use instead?

That's right.
You could use "smallint" instead which only uses 2 bytes.
If you want to prevent larger values to be inserted,
you could use a check constraint.

How do you ensure that a one-byte range type only occupies one byte?

If you use a smallint, it will use two bytes.

Is it because of the SQL standard, that PostgreSQL doesn't have a one-
byte type, too?

I didn't check, but I don't think so. That would be surprising.

It really doesn't contain one...

Quote:
Generally, I get the feeling the mainstream DBMS' around (PostgreSQL,
MySQL, Oracle, ...) don't like byte-wise types. Could it have to do
with two-byte memory alignment issues?

Maybe, but I guess that there is no hige demand for it.

Yours,
Laurenz Albe
Hmmm strange. I thought it might be the ideal size to store booleans
as well.

Karsten

Reply With Quote
  #7  
Old   
Karsten Wutzke
 
Posts: n/a

Default Re: One-byte integral type? - 09-07-2009 , 11:17 AM



On 7 Sep., 13:58, Thomas Kellerer <OTPXDAJCS... (AT) spammotel (DOT) com> wrote:
Quote:
Karsten Wutzke, 07.09.2009 13:06:

Generally, I get the feeling the mainstream DBMS' around (PostgreSQL,
MySQL, Oracle, ...) don't like byte-wise types. Could it have to do
with two-byte memory alignment issues?

What's the use for a single-byte datatype? Space consideration should not matter nowadays.

Yes that's a good point. I just wonder why the SQL standard has never
included a one-byte type back in the days when space consideration
still used to be an issue.

Karsten

Reply With Quote
  #8  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: One-byte integral type? - 09-08-2009 , 01:33 AM



Karsten Wutzke, 07.09.2009 18:16:
Quote:
Hmmm strange. I thought it might be the ideal size to store booleans
as well.
That's what the boolean type is for

Thomas

Reply With Quote
  #9  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: One-byte integral type? - 09-08-2009 , 04:04 AM



Karsten Wutzke wrote:
Quote:
Is it because of the SQL standard, that PostgreSQL doesn't have a one-
byte type, too?

I didn't check, but I don't think so. That would be surprising.

It really doesn't contain one...
Oh, what I meant is that I don't think that the SQL Standard
*forbids* it.

Yours,
Laurenz Albe

Reply With Quote
  #10  
Old   
Karsten Wutzke
 
Posts: n/a

Default Re: One-byte integral type? - 09-08-2009 , 04:45 AM



On 8 Sep., 08:33, Thomas Kellerer <OTPXDAJCS... (AT) spammotel (DOT) com> wrote:
Quote:
Karsten Wutzke, 07.09.2009 18:16:

Hmmm strange. I thought it might be the ideal size to store booleans
as well.

That's what the boolean type is for

Thomas
Yes, I just meant internally. Since I don't have a PostgreSQL running
anywhere, could you find out for me how many bytes are occupied by a
BOOLEAN, please? (it would be rather strange for PostgreSQL to store
BOOLEANs as byte, but not to offer a one-byte integral type...)

Karsten

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.