pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
To: Milen A. Radev <milen@radev.net>
Cc: pgadmin-support@postgresql.org
Cc: pgsql-sql@postgresql.org
Subject: Re: Alternative Serial
Date: Sun, 11 Mar 2007 12:08:59 -0300
Message-ID: <55c095e90703110808u567e9a1dr4d038b2b382b3a68@mail.gmail.com> (raw)
In-Reply-To: <et14pj$5u5$1@sea.gmane.org>
References: <55c095e90703110720o78dfcfeai2b31bbadf17582b7@mail.gmail.com>
	<et14pj$5u5$1@sea.gmane.org>

Yes you are right, I means sequences.

The second way is better for me that have Id (PK) fields not  defined  as
Sequences. Now it is much more difficult to change the  type of my PK than
define a Default value. I am just concerned about the consistency of this
sequence. Could you make me more easy ?

And about the cast I have found ?

nextval('mySerial_id'::regclass)

I ask again. What is regclass ? What does it really is.

Ezequias

2007/3/11, Milen A. Radev <milen@radev.net>:
>
> Ezequias Rodrigues da Rocha написа:
> > Hi list,
> >
> > I know that serials must be created like this.
>
> Actually no.
>
> > Create the Serial
>
> There is no db object 'Serial' you could create independently - you
> probably mean 'sequence'.
>
> >
> > Create a field table and reffers to the pre-created serial.
>
> You could and should create a field of (pseudo-)type 'serial' and be
> done with it.
>
> >
> > Now I noticed that it is possible to use the default value. I am almost
> > quite sure that this is an alternative way and non polite.
>
>
> The old and still working way to create a field that would function as
> surrogate key is to create a sequence, create a field in the table, mark
> it integer and set its default value to be the 'nextval' of the created
> sequence. That was too much typing for some (I'm included) and later a
> syntax sugar was added - the pseudo-type 'serial'.
>
> So the following syntax:
>
> CREATE TABLE example (
>    example_sid SERIAL NOT NULL PRIMARY KEY,
>    ...
> )
>
> is equivalen to:
>
>
> CREATE SEQUENCE example_example_sid_seq;
>
> CREATE TABLE example (
>    example_sid INTEGER PRIMARY KEY DEFAULT
> NEXVAL)('example_example_sid_seq'),
>    ...
> )
>
>
> As you could see - very convenient for the 99.9% of the cases.
>
> >
> > I would like to know if I am correct and what does it means:
> >
> > nextval('mySerial_id'::regclass)
> >
> > What is regclass ?
>
> Read here about 'regclass' (there is a note about it) -
> http://www.postgresql.org/docs/8.2/static/functions-sequence.html, but
> that should not be important to you.
>
>
> --
> Milen A. Radev
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org
>



-- 
Ezequias Rodrigues da Rocha
http://ezequiasrocha.blogspot.com/
use Mozilla Firefox:http://br.mozdev.org/firefox/


view thread (5+ messages)  latest in thread

Message-ID: <55c095e90703110808u567e9a1dr4d038b2b382b3a68@mail.gmail.com>
Permalink:  ../55c095e90703110808u567e9a1dr4d038b2b382b3a68@mail.gmail.com/
Also on:    postgresql.org/message-id/55c095e90703110808u567e9a1dr4d038b2b382b3a68@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ezequias.rocha@gmail.com, milen@radev.net, pgadmin-support@postgresql.org
  Subject: Re: Alternative Serial
  In-Reply-To: <55c095e90703110808u567e9a1dr4d038b2b382b3a68@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox