Re: Keeping track of updates/performances

Поиск
Список
Период
Сортировка
От Luca Ferrari
Тема Re: Keeping track of updates/performances
Дата
Msg-id CAKoxK+4c8fbLS9VKA47kuK_6ssDd99O3vFnu20Sfv1b0xrhZ0A@mail.gmail.com
обсуждение исходный текст
Ответ на Keeping track of updates/performances  (Romain Billon-Grand <billongrand@hotmail.fr>)
Список pgsql-novice
Ciao,

On Tue, Mar 17, 2015 at 9:06 AM, Romain Billon-Grand
<billongrand@hotmail.fr> wrote:
> 1/ I have been looking for built in options in postgres but I guess I have
> to build it myself...?
> Of course if Postgres already does it I am very happy, and all of the
> following quetsions are useless but I did not find this in the
> documentation...
>

You can use current_user and 'now'::timestamp for instance to get the
actual time and user.
Place this in a trigger for insert/update and you made it.



> Or, even if it exists, maybe I would better get it back from some user table
> such as
> CREATE TABLE users (username TEXT, role TEXT, id_user..); ??
>

What is the aim? There is the catalog for tracking users and roles.

> for timestamps, I guess triggers would be the best way to do the job, but I
> would like to have the whole table updated automatically without having to
> include this in all my update quieries...
>

and triggers will do the magic update as you want, so what is the
problem with triggers?

>
> 3/ once such a table is built like this for example
> CREATE TABLE track (creation TIMESTAMP, last_modification TIMESTAMP,
> created_by TEXT, lastmodified_by TEXT)
>
> What would be the advantages and drawbacks of this :
> CREATE TABLE anytable(...) INHERITS (tracks)
> vs this: CREATE TABLE anytable (...) LIKE tracks?

inheritance means that the new table will share columns with the
parent, while like will copy the DDL for the table and the constraint.
You should have a look at the documentation:
http://www.postgresql.org/docs/current/static/sql-createtable.html

Luca


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

Предыдущее
От: Felipe Santos
Дата:
Сообщение: Re: Keeping track of updates/performances
Следующее
От: Romain Billon-Grand
Дата:
Сообщение: Re: Keeping track of updates/performances