pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jackson, DeJuan <djackson@cpsgroup.com>
To: Hroi Sigurdsson <hroi@ninja.dk>
Cc: pgsql-sql@postgreSQL.org
Subject: RE: [SQL] DEFAULT confusion
Date: Wed, 8 Sep 1999 13:08:23 -0500
Message-ID: <D05EF808F2DFD211AE4A00105AA1B5D2519AB6@cpsmail> (raw)



> -----Original Message-----
> From:	Hroi Sigurdsson [SMTP:hroi@ninja.dk]
> Sent:	Tuesday, September 07, 1999 9:40 PM
> To:	pgsql-sql@postgreSQL.org
> Subject:	[SQL] DEFAULT confusion
> 
> Hello postgresql'ers (how do you pronounce that?).
> 
> Suppose i have the following sequence, table and index:
> 
> CREATE SEQUENCE stuff_seq; 
> CREATE TABLE stuff (
>         id      INTEGER DEFAULT NEXTVAL('stuff_seq') NOT NULL,
>         name    TEXT,
>         number  INTEGER
> );
> CREATE UNIQUE INDEX stuff_id ON tabel(id); 
> 
> Then to properly insert rows i have to
> 
> INSERT INTO tabel VALUES (NEXTVAL('tabel_seq'), "sometext", 123);
	Change the above line to:
	INSERT INTO stuff(name, number) VALUES ('sometext', 123);

	Hope this helps,
		DEJ

> I can't just
> INSERT INTO tabel VALUES (NULL, "something", 123);
> 
> Then what is the point of the DEFAULT clause? In other words: How do I
> get away with not specifying anything for id? And how (if
> possible/recommendable) do I force the id value to be nothing but
> NEXTVAL('stuff_seq'), ie. not just an arbitrary number?
> 
> In short I want to emulate MySQL's way of doing
> CREATE TABLE(
>         id      INT NOT NULL AUTO_INCREMENT,
>         name    TEXT,
>         int     INT,
>         UNIQUE(id)
> );
> 
> I hope I made myself sufficiently clear.
> 
> Thank you for your time.
> 
> 
> PS.
> Where can I get more information about the REFERENCES keyword and when
> will it be fully working in Postgres?
> PPS.
> Are there any books out there that cover Postgresql?
> -- 
> Hroi Sigurdsson
> hroi@ninja.dk
> 
> ************



view thread (9+ messages)

Message-ID: <D05EF808F2DFD211AE4A00105AA1B5D2519AB6@cpsmail>
Permalink:  ../D05EF808F2DFD211AE4A00105AA1B5D2519AB6@cpsmail/
Also on:    postgresql.org/message-id/D05EF808F2DFD211AE4A00105AA1B5D2519AB6@cpsmail

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: djackson@cpsgroup.com, hroi@ninja.dk
  Subject: Re: [SQL] DEFAULT confusion
  In-Reply-To: <D05EF808F2DFD211AE4A00105AA1B5D2519AB6@cpsmail>
  References: <D05EF808F2DFD211AE4A00105AA1B5D2519AB6@cpsmail>

* 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