serial data type

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

    serial data type

    Can I use the serial data type in lieu of an 'auto_number' field?

    I asked something like this some months ago and it seems that
    auto_number fields were addressed through a combination of triggers and
    procedures to ensure that there were do duplicate KEYS generated.

    Is it realistic to use the serial data type as a KEY?

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

  • Doug McNaught

    #2
    Re: serial data type

    Tom Allison <tallison@tacoc at.net> writes:
    [color=blue]
    > Can I use the serial data type in lieu of an 'auto_number' field?[/color]

    What are the exact semantics of an "auto_numbe r" field?
    [color=blue]
    > I asked something like this some months ago and it seems that
    > auto_number fields were addressed through a combination of triggers
    > and procedures to ensure that there were do duplicate KEYS generated.
    >
    > Is it realistic to use the serial data type as a KEY?[/color]

    Lots and lots of people do. If you're just looking for a unique key
    column for a single table, it works fine.

    -Doug
    --
    Let us cross over the river, and rest under the shade of the trees.
    --T. J. Jackson, 1863

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

    Comment

    • Tom Allison

      #3
      Re: serial data type



      Doug McNaught wrote:[color=blue][color=green]
      >>Is it realistic to use the serial data type as a KEY?[/color]
      >
      >
      > Lots and lots of people do. If you're just looking for a unique key
      > column for a single table, it works fine.
      >
      > -Doug[/color]

      This is essentially what I'm looking for.

      Any idea how to set up a timestamp=now on every insert/update ?

      ---------------------------(end of broadcast)---------------------------
      TIP 1: subscribe and unsubscribe commands go to majordomo@postg resql.org

      Comment

      • Doug McNaught

        #4
        Re: serial data type

        Tom Allison <tallison@tacoc at.net> writes:
        [color=blue]
        > Doug McNaught wrote:[color=green][color=darkred]
        >>>Is it realistic to use the serial data type as a KEY?[/color]
        >> Lots and lots of people do. If you're just looking for a unique key
        >> column for a single table, it works fine.
        >> -Doug[/color]
        >
        > This is essentially what I'm looking for.
        >
        > Any idea how to set up a timestamp=now on every insert/update ?[/color]

        Use a trigger.

        -Doug
        --
        Let us cross over the river, and rest under the shade of the trees.
        --T. J. Jackson, 1863

        ---------------------------(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

        • Joseph Healy

          #5
          Re: serial data type

          On Sat, Sep 25, 2004 at 07:20:23PM -0400, Tom Allison wrote:[color=blue]
          >
          > Any idea how to set up a timestamp=now on every insert/update ?[/color]

          when you create your table, use:

          create table mytable (
          id serial primary key,
          updated timestamp default(now()),
          mydata int4
          );

          Joe


          ---------------------------(end of broadcast)---------------------------
          TIP 5: Have you checked our extensive FAQ?



          Comment

          • Doug McNaught

            #6
            Re: serial data type

            Joseph Healy <joe_healy@dodo .com.au> writes:
            [color=blue]
            > On Sat, Sep 25, 2004 at 07:20:23PM -0400, Tom Allison wrote:[color=green]
            >>
            >> Any idea how to set up a timestamp=now on every insert/update ?[/color]
            >
            > when you create your table, use:
            >
            > create table mytable (
            > id serial primary key,
            > updated timestamp default(now()),
            > mydata int4
            > );[/color]

            That won't change the timestamp on UPDATE queries; you need a trigger
            for that.

            -Doug
            --
            Let us cross over the river, and rest under the shade of the trees.
            --T. J. Jackson, 1863

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

            Comment

            • Tom Allison

              #7
              Re: serial data type



              Doug McNaught wrote:[color=blue]
              > Joseph Healy <joe_healy@dodo .com.au> writes:
              >
              >[color=green]
              >>On Sat, Sep 25, 2004 at 07:20:23PM -0400, Tom Allison wrote:
              >>[color=darkred]
              >>>Any idea how to set up a timestamp=now on every insert/update ?[/color]
              >>
              >>when you create your table, use:
              >>
              >>create table mytable (
              >> id serial primary key,
              >> updated timestamp default(now()),
              >> mydata int4
              >>);[/color]
              >
              >
              > That won't change the timestamp on UPDATE queries; you need a trigger
              > for that.[/color]

              Thanks!
              Understood.

              I'll get to that tomorrow. Right now I'm working on data types and
              tables....

              ---------------------------(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...