int1?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CSN

    int1?

    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
    Yahoo Shopping is your guide to the latest deals and product reviews from the stores you love. Find sales and discounts on featured brands, shop for gifts, read our buying guides and more.


    ---------------------------(end of broadcast)---------------------------
    TIP 7: don't forget to increase your free space map settings

  • Shridhar Daithankar

    #2
    Re: int1?

    CSN wrote:
    [color=blue]
    > Is there any date type that can be used for 0-255
    > values? Like an "int1" or byte column.[/color]

    You can use a smallint with constraint.

    HTH


    Shridhar


    ---------------------------(end of broadcast)---------------------------
    TIP 8: explain analyze is your friend

    Comment

    • Ron Johnson

      #3
      Re: int1?

      On Thu, 2003-10-09 at 02:16, CSN wrote:[color=blue]
      > Is there any date type that can be used for 0-255
      > values? Like an "int1" or byte column.[/color]

      An int2 with a constraint on it.

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

      "Fear the Penguin!!"


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

      Comment

      • Sean Chittenden

        #4
        Re: int1?

        > Is there any date type that can be used for 0-255[color=blue]
        > values? Like an "int1" or byte column.[/color]

        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*).



        -sc

        --
        Sean Chittenden

        ---------------------------(end of broadcast)---------------------------
        TIP 6: Have you searched our list archives?



        Comment

        • Ron Johnson

          #5
          Re: int1?

          On Thu, 2003-10-09 at 03:19, Sean Chittenden wrote:[color=blue][color=green]
          > > Is there any date type that can be used for 0-255
          > > values? Like an "int1" or byte column.[/color]
          >
          > 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...-SPECIAL-TABLE[/color]

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

          --
          -----------------------------------------------------------------
          Ron Johnson, Jr. ron.l.johnson@c ox.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.


          ---------------------------(end of broadcast)---------------------------
          TIP 9: the planner will ignore your desire to choose an index scan if your
          joining column's datatypes do not match

          Comment

          • Karsten Hilbert

            #6
            Re: int1?

            > http://developer.postgresql.org/docs...-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

            ---------------------------(end of broadcast)---------------------------
            TIP 9: the planner will ignore your desire to choose an index scan if your
            joining column's datatypes do not match

            Comment

            • Stephan Szabo

              #7
              Re: int1?


              On Thu, 9 Oct 2003, Sean Chittenden wrote:
              [color=blue][color=green]
              > > Is there any date type that can be used for 0-255
              > > values? Like an "int1" or byte column.[/color]
              >
              > A SMALLINT is two bytes on disk, use "char" instead. This is a hidden[/color]

              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.
              [color=blue]
              > goodie in PostgreSQL and one that I wish was exposed via a more
              > conventional syntax (*hint hint*).[/color]

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


              ---------------------------(end of broadcast)---------------------------
              TIP 3: if posting/reading through Usenet, please send an appropriate
              subscribe-nomail command to majordomo@postg resql.org so that your
              message can get through to the mailing list cleanly

              Comment

              • Sean Chittenden

                #8
                Re: int1?

                > > > Is there any date type that can be used for 0-255 values? Like[color=blue][color=green][color=darkred]
                > > > an "int1" or byte column.[/color]
                > >
                > > A SMALLINT is two bytes on disk, use "char" instead. This is a hidden[/color]
                >
                > 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.[/color]

                *nods* I have explicit casts everywhere when dealing with "char" and
                it's far from being elegant or clean.
                [color=blue]
                >[color=green]
                > > goodie in PostgreSQL and one that I wish was exposed via a more
                > > conventional syntax (*hint hint*).[/color]
                >
                > If we were going to do that I think we'd be better off making a new
                > type and leaving "char" alone.
                >[/color]

                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

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

                Comment

                • Ron Johnson

                  #9
                  Domains (was Re: int1?)

                  On Thu, 2003-10-09 at 12:54, Sean Chittenden wrote:[color=blue][color=green][color=darkred]
                  > > > > 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[/color]
                  > >
                  > > 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.[/color]
                  >
                  > *nods* I have explicit casts everywhere when dealing with "char" and
                  > it's far from being elegant or clean.
                  >[color=green]
                  > >[color=darkred]
                  > > > goodie in PostgreSQL and one that I wish was exposed via a more
                  > > > conventional syntax (*hint hint*).[/color]
                  > >
                  > > If we were going to do that I think we'd be better off making a new
                  > > type and leaving "char" alone.
                  > >[/color]
                  >
                  > 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[/color]


                  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@c ox.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


                  ---------------------------(end of broadcast)---------------------------
                  TIP 4: Don't 'kill -9' the postmaster

                  Comment

                  • Bruno Wolff III

                    #10
                    Re: Domains (was Re: int1?)

                    On Thu, Oct 09, 2003 at 14:28:57 -0500,
                    Ron Johnson <ron.l.johnson@ cox.net> wrote:[color=blue]
                    >
                    > http://www.postgresql.org/docs/7.3/s...atedomain.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?[/color]

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

                    ---------------------------(end of broadcast)---------------------------
                    TIP 4: Don't 'kill -9' the postmaster

                    Comment

                    • Ron Johnson

                      #11
                      Re: Domains (was Re: int1?)

                      On Thu, 2003-10-09 at 14:46, Bruno Wolff III wrote:[color=blue]
                      > On Thu, Oct 09, 2003 at 14:28:57 -0500,
                      > Ron Johnson <ron.l.johnson@ cox.net> wrote:[color=green]
                      > >
                      > > http://www.postgresql.org/docs/7.3/s...atedomain.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?[/color]
                      >
                      > You need to use 7.4. In 7.3 you couldn't use check constraints with domains.[/color]

                      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@c ox.net
                      Jefferson, LA USA

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


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

                      Comment

                      • Peter Eisentraut

                        #12
                        Re: Domains (was Re: int1?)

                        Ron Johnson writes:
                        [color=blue]
                        > 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?[/color]

                        You would have to wait for PostgreSQL 7.4.

                        --
                        Peter Eisentraut peter_e@gmx.net


                        ---------------------------(end of broadcast)---------------------------
                        TIP 8: explain analyze is your friend

                        Comment

                        • Bruno Wolff III

                          #13
                          Re: Domains (was Re: int1?)

                          On Thu, Oct 09, 2003 at 14:46:08 -0500,
                          Ron Johnson <ron.l.johnson@ cox.net> wrote:[color=blue]
                          > On Thu, 2003-10-09 at 14:46, Bruno Wolff III wrote:[color=green]
                          > > On Thu, Oct 09, 2003 at 14:28:57 -0500,
                          > > Ron Johnson <ron.l.johnson@ cox.net> wrote:[color=darkred]
                          > > >
                          > > > http://www.postgresql.org/docs/7.3/s...atedomain.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?[/color]
                          > >
                          > > You need to use 7.4. In 7.3 you couldn't use check constraints with domains.[/color]
                          >
                          > So is there a documentation "bug", or, what kind of constraints
                          > can be placed on domains besides { NOT NULL | NULL }?[/color]

                          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.

                          ---------------------------(end of broadcast)---------------------------
                          TIP 7: don't forget to increase your free space map settings

                          Comment

                          • Ron Johnson

                            #14
                            Re: Domains (was Re: int1?)

                            On Thu, 2003-10-09 at 15:13, Bruno Wolff III wrote:[color=blue]
                            > On Thu, Oct 09, 2003 at 14:46:08 -0500,
                            > Ron Johnson <ron.l.johnson@ cox.net> wrote:[color=green]
                            > > On Thu, 2003-10-09 at 14:46, Bruno Wolff III wrote:[color=darkred]
                            > > > 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/s...atedomain.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.[/color]
                            > >
                            > > So is there a documentation "bug", or, what kind of constraints
                            > > can be placed on domains besides { NOT NULL | NULL }?[/color]
                            >
                            > 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.[/color]

                            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@c ox.net
                            Jefferson, LA USA

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


                            ---------------------------(end of broadcast)---------------------------
                            TIP 4: Don't 'kill -9' the postmaster

                            Comment

                            • Joe Conway

                              #15
                              Re: int1?

                              Ron Johnson wrote:[color=blue]
                              > On Thu, 2003-10-09 at 02:16, CSN wrote:
                              >[color=green]
                              >>Is there any date type that can be used for 0-255
                              >>values? Like an "int1" or byte column.[/color]
                              >
                              > An int2 with a constraint on it.
                              >[/color]

                              You can use the data type "char" (with the quotes, and without a (n)
                              decoration). See:

                              near the bottom of the page.

                              Joe


                              ---------------------------(end of broadcast)---------------------------
                              TIP 3: if posting/reading through Usenet, please send an appropriate
                              subscribe-nomail command to majordomo@postg resql.org so that your
                              message can get through to the mailing list cleanly

                              Comment

                              Working...