Re: Calculation Functions between Columns

Поиск
Список
Период
Сортировка
От Mark Stosberg
Тема Re: Calculation Functions between Columns
Дата
Msg-id slrnclgl4s.1jnh.mark@tanagra.summersault.com
обсуждение исходный текст
Ответ на Calculation Functions between Columns  (Neacal <deb@mac.ppc>)
Список pgsql-novice
On 2004-09-26, Neacal <deb@mac.ppc> wrote:
>
> In the O'Reilly book, I can find a number of functions described which
> look like tools for the job, but they are all mentioned as methods to
> SELECT FROM, rather than INSERT INTO.  I haven't found anything (so
> far) on columns that can depend on/derive from other columns.  Have I
> missed something, or doesn't PostgreSQL do this sort of thing?

What you are describing sounds like a good use for a "view" to me.

Here's an example:

CREATE TABLE sales (
    amount            int,
    quantity        int
);

INSERT into sales values (2,3);

CREATE view sub_total as
    SELECT (amount * quantity) as subtotal
    FROM sales;

SELECT * from sub_total;

 subtotal
----------
        6

#################

There are more complex solutions as well, such as using triggers to
automatically update the value of one column based on others.

    Mark

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

Предыдущее
От: Oliver Fromme
Дата:
Сообщение: Re: Calculation in update query
Следующее
От: Mark Stosberg
Дата:
Сообщение: Re: max_connections not changing