mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
Add an example of attaching a default value to an updatable view.
This is probably the single most useful thing that ALTER VIEW can do, particularly now that we have auto-updatable views. So show an explicit example.
This commit is contained in:
@ -154,7 +154,19 @@ ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RESET
|
|||||||
<literal>bar</literal>:
|
<literal>bar</literal>:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
ALTER VIEW foo RENAME TO bar;
|
ALTER VIEW foo RENAME TO bar;
|
||||||
</programlisting></para>
|
</programlisting>
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
To attach a default column value to an updatable view:
|
||||||
|
<programlisting>
|
||||||
|
CREATE TABLE base_table (id int, ts timestamptz);
|
||||||
|
CREATE VIEW a_view AS SELECT * FROM base_table;
|
||||||
|
ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
|
||||||
|
INSERT INTO base_table(id) VALUES(1); -- ts will receive a NULL
|
||||||
|
INSERT INTO a_view(id) VALUES(2); -- ts will receive the current time
|
||||||
|
</programlisting>
|
||||||
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
|
Reference in New Issue
Block a user