defaults referencing other columns?

Поиск
Список
Период
Сортировка
От James Cloos
Тема defaults referencing other columns?
Дата
Msg-id m38xl0aim3.fsf@lugabout.jhcloos.org
обсуждение исходный текст
Ответы Re: defaults referencing other columns?  ("Jasbinder Bali" <jsbali@gmail.com>)
Re: defaults referencing other columns?  (Richard Broersma Jr <rabroersma@yahoo.com>)
Список pgsql-novice
Can a default value reference the value specified for one of the other
columns in the insert?

If you have something 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@jhcloos.com>         OpenPGP: 0xED7DAEA6

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Eric M. Cherry"
Дата:
Сообщение: Progress and Questions
Следующее
От: James Cloos
Дата:
Сообщение: function parameters