Defining a "tinyint" data type - one byte unsigned

Started by Shachar Shemeshover 22 years ago8 messagespatches
Jump to latest
#1Shachar Shemesh
psql@shemesh.biz

Hi all,

Attached is a patch to implement "tinyint". This is a one byte unsigned
integer type. It is required for porting applications built for
sql-server that work in binary mode.

This is my first attempt at hacking postgresql proper, so please be
patient with me. I have run it on 7.5 locally, and it passes all tests.
If there was anything else I should have done before submitting it,
please let me know.

I chose "10" as the oid for the new type, as it seems to sort well in
the types sizes list (21 is int2, 23 is int4). I took the OID for the
conversion functions from the top to avoid collisions.

Also, I'm interested in knowning whether there is any chance of
introducing anything of this like into 7.4, or whether I should create
that as an extrenal type there.

Thanks,

Shachar

--
Shachar Shemesh
Lingnu Open Systems Consulting
http://www.lingnu.com/

Attachments:

tinyint.difftext/x-patch; name=tinyint.diffDownload+225-21
#2Dennis Bjorklund
db@zigo.dhs.org
In reply to: Shachar Shemesh (#1)
Re: Defining a "tinyint" data type - one byte unsigned

On Thu, 11 Mar 2004, Shachar Shemesh wrote:

Attached is a patch to implement "tinyint". This is a one byte unsigned
integer type.

It's a bit strange that this int is unsigned and the others are signed.

--
/Dennis Bj�rklund

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Shachar Shemesh (#1)
Re: Defining a "tinyint" data type - one byte unsigned

Shachar Shemesh <psql@shemesh.biz> writes:

Attached is a patch to implement "tinyint".

I don't think we've really solved the numeric-hierarchy casting problems
well enough to be able to stand adding another member of the hierarchy.
In particular, what impact is this going to have on implicit typing of
integer constants?

regards, tom lane

#4Shachar Shemesh
psql@shemesh.biz
In reply to: Dennis Bjorklund (#2)
Re: Defining a "tinyint" data type - one byte unsigned

Dennis Bjorklund wrote:

On Thu, 11 Mar 2004, Shachar Shemesh wrote:

Attached is a patch to implement "tinyint". This is a one byte unsigned
integer type.

It's a bit strange that this int is unsigned and the others are signed.

Not that strange if you consider the fact that making it signed will not
leave much room for actually using it.

In any case, that's just the way it is:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ia-iz_3ss4.asp

--
Shachar Shemesh
Lingnu Open Systems Consulting
http://www.lingnu.com/

#5Shachar Shemesh
psql@shemesh.biz
In reply to: Tom Lane (#3)
Re: Defining a "tinyint" data type - one byte unsigned

Tom Lane wrote:

Shachar Shemesh <psql@shemesh.biz> writes:

Attached is a patch to implement "tinyint".

I don't think we've really solved the numeric-hierarchy casting problems
well enough to be able to stand adding another member of the hierarchy.
In particular, what impact is this going to have on implicit typing of
integer constants?

regards, tom lane

The nice thing about a one byte integer is that it's at the very bottom
of the food chain. Since casting upwards is implicit and downwards is
explicit, NOTHING casts implicitly to it. As such I'm hoping (like I
said in my original post - I'm no expert) that this will be a harmless
addition.

If there is anything you can think of that will allow me to verify this
claim, do let me know.

--
Shachar Shemesh
Lingnu Open Systems Consulting
http://www.lingnu.com/

#6Shachar Shemesh
psql@shemesh.biz
In reply to: Shachar Shemesh (#5)
Re: Defining a "tinyint" data type - one byte unsigned

Shachar Shemesh wrote:

Tom Lane wrote:

I don't think we've really solved the numeric-hierarchy casting problems
well enough to be able to stand adding another member of the hierarchy.
In particular, what impact is this going to have on implicit typing of
integer constants?

regards, tom lane

The nice thing about a one byte integer is that it's at the very
bottom of the food chain. Since casting upwards is implicit and
downwards is explicit, NOTHING casts implicitly to it. As such I'm
hoping (like I said in my original post - I'm no expert) that this
will be a harmless addition.

If there is anything you can think of that will allow me to verify
this claim, do let me know.

Hmm - replying to my own post.

I did cut one corner, in that I did not implement tiny->int8 and
tiny->non integers yet. That is, however, an implementation detail
rather than a principal problem. If that is the whole problem, I'll add
those as well. I would rather, before doing the extra work, hear that
this is indeed all that is needed to get it in.

Having said that, some sort of implicit casts of implicit casts results
does seem necessary in postgres. I don't think that leaving this patch
out will be the way to solve this.

--
Shachar Shemesh
Lingnu Open Systems Consulting
http://www.lingnu.com/

#7Shachar Shemesh
psql@shemesh.biz
In reply to: Shachar Shemesh (#6)
Re: Defining a "tinyint" data type - one byte unsigned

Shachar Shemesh wrote:

Hmm - replying to my own post.

I did cut one corner, in that I did not implement tiny->int8 and
tiny->non integers yet. That is, however, an implementation detail
rather than a principal problem. If that is the whole problem, I'll
add those as well. I would rather, before doing the extra work, hear
that this is indeed all that is needed to get it in.

Replying to my own post again!

The documentation for SQL Server says this
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ia-iz_3ss4.asp):

Functions will return *bigint* only if the parameter expression is a
*bigint* data type. SQL Server will not automatically promote other
integer data types (*tinyint*, *smallint*, and *int*) to *bigint*.

Perhaps Postgres is not alone with it's casting problems.

--
Shachar Shemesh
Lingnu Open Systems Consulting
http://www.lingnu.com/

#8Dennis Bjorklund
db@zigo.dhs.org
In reply to: Shachar Shemesh (#4)
Re: Defining a "tinyint" data type - one byte unsigned

On Thu, 11 Mar 2004, Shachar Shemesh wrote:

It's a bit strange that this int is unsigned and the others are signed.

Not that strange if you consider the fact that making it signed will not
leave much room for actually using it.

In any case, that's just the way it is:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ia-iz_3ss4.asp

Well, in another very popular database it's signed:

http://www.mysql.com/documentation/mysql/bychapter/manual_Column_types.html#Numeric_types

If anything I would like a unsigned modifier to all integer types.

--
/Dennis Bj�rklund