int1?

Started by CSNover 22 years ago30 messagesgeneral
Jump to latest
#1CSN
cool_screen_name90001@yahoo.com

Is there any date type that can be used for 0-255
values? Like an "int1" or byte column.

CSN

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

#2Shridhar Daithankar
shridhar_daithankar@persistent.co.in
In reply to: CSN (#1)
Re: int1?

CSN wrote:

Is there any date type that can be used for 0-255
values? Like an "int1" or byte column.

You can use a smallint with constraint.

HTH

Shridhar

#3Ron Johnson
ron.l.johnson@cox.net
In reply to: CSN (#1)
Re: int1?

On Thu, 2003-10-09 at 02:16, CSN wrote:

Is there any date type that can be used for 0-255
values? Like an "int1" or byte column.

An int2 with a constraint on it.

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

"Fear the Penguin!!"

#4Sean Chittenden
sean@chittenden.org
In reply to: CSN (#1)
Re: int1?

Is there any date type that can be used for 0-255
values? Like an "int1" or byte column.

A SMALLINT is two bytes on disk, use "char" instead. This is a hidden
goodie in PostgreSQL and one that I wish was exposed via a more
conventional syntax (*hint hint*).

http://developer.postgresql.org/docs/postgres/datatype-character.html#DATATYPE-CHARACTER-SPECIAL-TABLE

-sc

--
Sean Chittenden

#5Ron Johnson
ron.l.johnson@cox.net
In reply to: Sean Chittenden (#4)
Re: int1?

On Thu, 2003-10-09 at 03:19, Sean Chittenden wrote:

Is there any date type that can be used for 0-255
values? Like an "int1" or byte column.

A SMALLINT is two bytes on disk, use "char" instead. This is a hidden
goodie in PostgreSQL and one that I wish was exposed via a more
conventional syntax (*hint hint*).

http://developer.postgresql.org/docs/postgres/datatype-character.html#DATATYPE-CHARACTER-SPECIAL-TABLE

Wouldn't that be, though, a signed byte? The OP wants unsigned.

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

The purpose of the military isn't to pay your college tuition or
give you a little extra income; it's to "kill people and break
things".
Surprisingly, not everyone understands that.

#6Karsten Hilbert
Karsten.Hilbert@gmx.net
In reply to: Sean Chittenden (#4)
Re: int1?

http://developer.postgresql.org/docs/postgres/datatype-character.html#DATATYPE-CHARACTER-SPECIAL-TABLE

Is it unsafe practice to use the datatype "name" for
attributes that hold table or column names etc ?

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

#7Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Sean Chittenden (#4)
Re: int1?

On Thu, 9 Oct 2003, Sean Chittenden wrote:

Is there any date type that can be used for 0-255
values? Like an "int1" or byte column.

A SMALLINT is two bytes on disk, use "char" instead. This is a hidden

However "char" has some serious deficiencies IIRC, such as the fact that
there's no int<->"char" casts and it's standard I/O format is characters.
You can use ascii and chr to get around some of that, but it's ugly.

goodie in PostgreSQL and one that I wish was exposed via a more
conventional syntax (*hint hint*).

If we were going to do that I think we'd be better off making a new type
and leaving "char" alone.

#8Sean Chittenden
sean@chittenden.org
In reply to: Stephan Szabo (#7)
Re: int1?

Is there any date type that can be used for 0-255 values? Like
an "int1" or byte column.

A SMALLINT is two bytes on disk, use "char" instead. This is a hidden

However "char" has some serious deficiencies IIRC, such as the fact
that there's no int<->"char" casts and it's standard I/O format is
characters. You can use ascii and chr to get around some of that,
but it's ugly.

*nods* I have explicit casts everywhere when dealing with "char" and
it's far from being elegant or clean.

goodie in PostgreSQL and one that I wish was exposed via a more
conventional syntax (*hint hint*).

If we were going to do that I think we'd be better off making a new
type and leaving "char" alone.

You won't hear any disagreements from me on this one. I've
sufficiently abused "char" as a 1 byte storage field and would love to
see an int1 or tinyint datatype added to cover this situation. -sc

--
Sean Chittenden

#9Ron Johnson
ron.l.johnson@cox.net
In reply to: Sean Chittenden (#8)
Domains (was Re: int1?)

On Thu, 2003-10-09 at 12:54, Sean Chittenden wrote:

Is there any date type that can be used for 0-255 values? Like
an "int1" or byte column.

A SMALLINT is two bytes on disk, use "char" instead. This is a hidden

However "char" has some serious deficiencies IIRC, such as the fact
that there's no int<->"char" casts and it's standard I/O format is
characters. You can use ascii and chr to get around some of that,
but it's ugly.

*nods* I have explicit casts everywhere when dealing with "char" and
it's far from being elegant or clean.

goodie in PostgreSQL and one that I wish was exposed via a more
conventional syntax (*hint hint*).

If we were going to do that I think we'd be better off making a new
type and leaving "char" alone.

You won't hear any disagreements from me on this one. I've
sufficiently abused "char" as a 1 byte storage field and would love to
see an int1 or tinyint datatype added to cover this situation. -sc

http://www.postgresql.org/docs/7.3/static/sql-createdomain.html
CREATE DOMAIN domainname [AS] data_type
[ DEFAULT default_expr ]
[ constraint [, ... ] ]

where constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL }

test1=# create domain d_tinyint as smallint constraint chk_tinyint CHECK (smallint between 0 and 255);
ERROR: DefineDomain: CHECK Constraints not supported

So, how would I create a domain that limits a smallint?

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

"You can either have software quality or you can have pointer
arithmetic, but you cannot have both at the same time."
Bertrand Meyer

#10Ron Johnson
ron.l.johnson@cox.net
In reply to: CSN (#1)
Re: Domains (was Re: int1?)

On Thu, 2003-10-09 at 14:46, Bruno Wolff III wrote:

On Thu, Oct 09, 2003 at 14:28:57 -0500,
Ron Johnson <ron.l.johnson@cox.net> wrote:

http://www.postgresql.org/docs/7.3/static/sql-createdomain.html
CREATE DOMAIN domainname [AS] data_type
[ DEFAULT default_expr ]
[ constraint [, ... ] ]

where constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL }

test1=# create domain d_tinyint as smallint constraint chk_tinyint CHECK (smallint between 0 and 255);
ERROR: DefineDomain: CHECK Constraints not supported

So, how would I create a domain that limits a smallint?

You need to use 7.4. In 7.3 you couldn't use check constraints with domains.

So is there a documentation "bug", or, what kind of constraints
can be placed on domains besides { NOT NULL | NULL }?

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

Causation does NOT equal correlation !!!!!!!!

#11Bruno Wolff III
bruno@wolff.to
In reply to: Ron Johnson (#9)
Re: Domains (was Re: int1?)

On Thu, Oct 09, 2003 at 14:28:57 -0500,
Ron Johnson <ron.l.johnson@cox.net> wrote:

http://www.postgresql.org/docs/7.3/static/sql-createdomain.html
CREATE DOMAIN domainname [AS] data_type
[ DEFAULT default_expr ]
[ constraint [, ... ] ]

where constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL }

test1=# create domain d_tinyint as smallint constraint chk_tinyint CHECK (smallint between 0 and 255);
ERROR: DefineDomain: CHECK Constraints not supported

So, how would I create a domain that limits a smallint?

You need to use 7.4. In 7.3 you couldn't use check constraints with domains.

#12Peter Eisentraut
peter_e@gmx.net
In reply to: Ron Johnson (#9)
Re: Domains (was Re: int1?)

Ron Johnson writes:

test1=# create domain d_tinyint as smallint constraint chk_tinyint CHECK (smallint between 0 and 255);
ERROR: DefineDomain: CHECK Constraints not supported

So, how would I create a domain that limits a smallint?

You would have to wait for PostgreSQL 7.4.

--
Peter Eisentraut peter_e@gmx.net

#13Bruno Wolff III
bruno@wolff.to
In reply to: Ron Johnson (#10)
Re: Domains (was Re: int1?)

On Thu, Oct 09, 2003 at 14:46:08 -0500,
Ron Johnson <ron.l.johnson@cox.net> wrote:

On Thu, 2003-10-09 at 14:46, Bruno Wolff III wrote:

On Thu, Oct 09, 2003 at 14:28:57 -0500,
Ron Johnson <ron.l.johnson@cox.net> wrote:

http://www.postgresql.org/docs/7.3/static/sql-createdomain.html
CREATE DOMAIN domainname [AS] data_type
[ DEFAULT default_expr ]
[ constraint [, ... ] ]

where constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL }

test1=# create domain d_tinyint as smallint constraint chk_tinyint CHECK (smallint between 0 and 255);
ERROR: DefineDomain: CHECK Constraints not supported

So, how would I create a domain that limits a smallint?

You need to use 7.4. In 7.3 you couldn't use check constraints with domains.

So is there a documentation "bug", or, what kind of constraints
can be placed on domains besides { NOT NULL | NULL }?

I think the documentation is correct. As I read it it says that only NOT NULL
and NULL constraints are allowed. This is easy to overlook. I know I got
caught by this when I tried it.

I started using 7.4 pretty early on since I wanted to use check constraints
in earthdistance to have a domain that represented points on the surface of
the earth on top of the cube data type.

#14Ron Johnson
ron.l.johnson@cox.net
In reply to: Bruno Wolff III (#13)
Re: Domains (was Re: int1?)

On Thu, 2003-10-09 at 15:13, Bruno Wolff III wrote:

On Thu, Oct 09, 2003 at 14:46:08 -0500,
Ron Johnson <ron.l.johnson@cox.net> wrote:

On Thu, 2003-10-09 at 14:46, Bruno Wolff III wrote:

On Thu, Oct 09, 2003 at 14:28:57 -0500,
Ron Johnson <ron.l.johnson@cox.net> wrote:

http://www.postgresql.org/docs/7.3/static/sql-createdomain.html
CREATE DOMAIN domainname [AS] data_type
[ DEFAULT default_expr ]
[ constraint [, ... ] ]

where constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL }

test1=# create domain d_tinyint as smallint constraint chk_tinyint CHECK (smallint between 0 and 255);
ERROR: DefineDomain: CHECK Constraints not supported

So, how would I create a domain that limits a smallint?

You need to use 7.4. In 7.3 you couldn't use check constraints with domains.

So is there a documentation "bug", or, what kind of constraints
can be placed on domains besides { NOT NULL | NULL }?

I think the documentation is correct. As I read it it says that only NOT NULL
and NULL constraints are allowed. This is easy to overlook. I know I got
caught by this when I tried it.

test1=# create domain foo as smallint not null;
CREATE DOMAIN

test1=# create domain bar as smallint CONSTRAINT wiggle not null;
CREATE DOMAIN

Oh, ok. Stuff in [] is not necessary. Still confusing.

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

The difference between drunken sailors and Congressmen is that
drunken sailors spend their own money.

#15Joe Conway
mail@joeconway.com
In reply to: Ron Johnson (#3)
Re: int1?

Ron Johnson wrote:

On Thu, 2003-10-09 at 02:16, CSN wrote:

Is there any date type that can be used for 0-255
values? Like an "int1" or byte column.

An int2 with a constraint on it.

You can use the data type "char" (with the quotes, and without a (n)
decoration). See:
http://www.postgresql.org/docs/view.php?version=7.3&amp;idoc=0&amp;file=datatype-character.html
near the bottom of the page.

Joe

#16CSN
cool_screen_name90001@yahoo.com
In reply to: Sean Chittenden (#8)
Re: int1? types?

Would you be able to roll your own int1's with types?

http://www.postgresql.org/docs/7.3/interactive/xtypes.html

CSN

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

#17elein
elein@varlena.com
In reply to: CSN (#16)
Re: int1? types?

I don't think that you can create a genuine one byte datatype.
The resulting type would probably be four bytes long, even if
you create a one byte by-value data type. The one byte would
be packaged in a 4 byte container for passing around the server.

Can anyone confirm or deny this? This was certainly the
case in Informix and Illustra.

--elein
elein@varlena.com

Show quoted text

On Fri, Oct 10, 2003 at 11:37:14AM -0700, CSN wrote:

Would you be able to roll your own int1's with types?

http://www.postgresql.org/docs/7.3/interactive/xtypes.html

CSN

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

#18Joe Conway
mail@joeconway.com
In reply to: elein (#17)
Re: int1? types?

elein wrote:

I don't think that you can create a genuine one byte datatype.
The resulting type would probably be four bytes long, even if
you create a one byte by-value data type. The one byte would
be packaged in a 4 byte container for passing around the server.

Can anyone confirm or deny this?

See my other post. The type exists and is called "char". See the bottom
of this page:
http://www.postgresql.org/docs/view.php?version=7.3&amp;idoc=0&amp;file=datatype-character.html

Joe

#19elein
elein@varlena.com
In reply to: Joe Conway (#18)
Re: int1? types?

The "char" type has special handling built into the server
if I recall correctly and that is part of the reason it
does not behave correctly in some cases. But I think it is
still schlepped around as a DATUM which is a four byte value.

What I meant was a user defined single byte data type.
I don't think it can be done since it needs to be packaged
as a DATUM.

elein

Show quoted text

On Fri, Oct 10, 2003 at 06:07:00PM -0700, Joe Conway wrote:

elein wrote:

I don't think that you can create a genuine one byte datatype.
The resulting type would probably be four bytes long, even if
you create a one byte by-value data type. The one byte would
be packaged in a 4 byte container for passing around the server.

Can anyone confirm or deny this?

See my other post. The type exists and is called "char". See the bottom
of this page:
http://www.postgresql.org/docs/view.php?version=7.3&amp;idoc=0&amp;file=datatype-character.html

Joe

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

#20Joe Conway
mail@joeconway.com
In reply to: elein (#19)
Re: int1? types?

elein wrote:

The "char" type has special handling built into the server
if I recall correctly and that is part of the reason it
does not behave correctly in some cases. But I think it is
still schlepped around as a DATUM which is a four byte value.

What I meant was a user defined single byte data type.
I don't think it can be done since it needs to be packaged
as a DATUM.

No, "char" is exactly one byte. See the doc, or the source:
http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/utils/adt/char.c?rev=1.38&amp;content-type=text/x-cvsweb-markup

Joe

#21Manfred Koizar
mkoi-pg@aon.at
In reply to: elein (#17)
#22elein
elein@varlena.com
In reply to: Manfred Koizar (#21)
#23Dennis Gearon
gearond@fireserve.net
In reply to: elein (#22)
#24Tom Lane
tgl@sss.pgh.pa.us
In reply to: Sean Chittenden (#8)
#25Sean Chittenden
sean@chittenden.org
In reply to: Tom Lane (#24)
#26Rick Seeger
rick@nettheory.com
In reply to: Sean Chittenden (#25)
#27Rick Seeger
rick@nettheory.com
In reply to: Rick Seeger (#26)
#28Ron Johnson
ron.l.johnson@cox.net
In reply to: Rick Seeger (#27)
#29Peter Eisentraut
peter_e@gmx.net
In reply to: Rick Seeger (#27)
#30Rick Seeger
rick@nettheory.com
In reply to: Peter Eisentraut (#29)