Re: Parent Id

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Gene Vital <genevital(at)karibe(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Parent Id
Date: 2003-10-10 01:30:32
Message-ID: 20031010013032.GA18596@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 09, 2003 at 17:09:33 -0400,
Gene Vital <genevital(at)karibe(dot)com> wrote:
> ok, I am new to Postgres so could you give a little better explanation
> of this ??
>
> I haven't created any sequence for this I am just using a type serial
> field. will I have to create a sequence for it?

When you use the serial type a sequence is automatically created for you.
The name is tablename_columnname_seq unless that string is too long
(> 64 characters I think). The actual name used gets printed as a notice
when you create the table.

>
> Here is my code to create the tables
>
> CREATE TABLE workstations (station_id INT4 PRIMARY KEY, name
> VARCHAR(50), description VARCHAR(250))
>
> CREATE TABLE wsoptions (option_id SERIAL PRIMARY KEY, station_id INT4
> REFERENCES workstations (station_id) ON DELETE CASCADE, type
> VARCHAR(20), data TEXT)
>
>
>
> insert into workstations (name, description)
> values("new", "This is a test")
>
> insert into wsoptions (stations_id, type, data)
> values( ????, "LOCATION", "10th floor outer, office 27")

The second insert should be:
insert into wsoptions (stations_id, type, data)
values( currval('workstations_station_id_seq'),
'LOCATION', '10th floor outer, office 27')

Also note that you need to use single quotes for data values. Double
quotes are used for the names of database objects.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marsh Ray 2003-10-10 01:44:17 Re: Humor me: Postgresql vs. MySql (esp. licensing)
Previous Message G Lam 2003-10-10 01:03:40 PG tools