Re: defaults referencing other columns?

From: "Jasbinder Bali" <jsbali(at)gmail(dot)com>
To: "James Cloos" <cloos(at)jhcloos(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: defaults referencing other columns?
Date: 2006-09-03 22:24:54
Message-ID: a47902760609031524o7e11be30sdea494edc743de76@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

There is something called Rule on a table.

http://www.postgresql.org/docs/8.1/interactive/sql-createrule.html

This might help.

Thanks,
~Jas

On 9/3/06, James Cloos <cloos(at)jhcloos(dot)com> wrote:
>
> Can a default value reference the value specified for one of the other
> columns in the insert?
>
> If you have like:
>
> CREATE TABLE foo ( id INT PRIMARY KEY,
> name TEXT NOT NULL,
> bar TEXT );
>
> can foo.bar have a default that is the result of calling a function on
> the value currently being inserted into foo.id or foo.name?
>
> I'd like something along the lines of:
>
> bar TEXT DEFAULT somefunc(id)
>
> but how does one specify that the value to be passed to the funtion is
> the exact value that insert is inserting into the foo.id column?
>
> And will it work even when the value being inserted into foo.id is
> itself the result of a function? (I presume so, but ....)
>
> -JimC
> --
> James Cloos <cloos(at)jhcloos(dot)com> OpenPGP: 0xED7DAEA6
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Richard Broersma Jr 2006-09-04 01:46:50 Re: defaults referencing other columns?
Previous Message Bruno Wolff III 2006-09-03 19:30:53 Re: Progress and Questions