Re : overriding default value in inherited column (+ set_value function)

From: Nico <nicod(at)tiscalinet(dot)it>
To: pgsql-general(at)postgresql(dot)org
Cc: "Matt Magoffin" <mmagoffin(at)proxicom(dot)com>
Subject: Re : overriding default value in inherited column (+ set_value function)
Date: 2001-03-20 15:02:04
Message-ID: 01032014024502.01280@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Actually not possible with the "DEFAULT" sintax inside the CREATE TABLE.
Instead, you could use explicit triggers, for example:

CREATE table foo (
"type" int2
);

CREATE table bar (
"type" int2
) INHERITS (foo);

CREATE TRIGGER set_default_value BEFORE INSERT
ON foo FOR EACH ROW
EXECUTE PROCEDURE set_value("type", 0);

CREATE TRIGGER set_default_value BEFORE INSERT
ON bar FOR EACH ROW
EXECUTE PROCEDURE set_value("type", 1);

The function set_value has to be written in C language (plpgsql lang doesn't
allow parameter passing for trigger functions).

Has someone already written that function?

regards, nico

> From: "Matt Magoffin" <mmagoffin(at)proxicom(dot)com>
> X-Newsgroups: comp.databases.postgresql.general
> Subject: overriding default value in inherited column
> Date: Mon, 19 Mar 2001 18:39:27 -0800
>
> Is there an easy way to override the defined default value of a column in
> an inherited table? For example:
>
> CREATE table foo (
> "type" int2 DEFAULT 0
> );
>
> CREATE table bar (
> "type" int2 DEFAULT 1
> ) INHERITS (foo);
>
> This gives the error:
>
> ERROR: CREATE TABLE: attribute "type" already exists in inherited schema
>
> which is understandable. In essence what I want to do is have each table
> schema default to a different value.
>
> -- m@

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gilles DAROLD 2001-03-20 15:12:39 Re: postgreSQL db temporary on Microsoft IIS 4.0
Previous Message Mayers, Philip J 2001-03-20 11:59:38 RE: Migrating from MS SQL 7