Skip to content

Commit 3a1f8cd

Browse files
committed
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.
1 parent 0343a59 commit 3a1f8cd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

doc/src/sgml/ref/alter_view.sgml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,19 @@ ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RESET
154154
<literal>bar</literal>:
155155
<programlisting>
156156
ALTER VIEW foo RENAME TO bar;
157-
</programlisting></para>
157+
</programlisting>
158+
</para>
159+
160+
<para>
161+
To attach a default column value to an updatable view:
162+
<programlisting>
163+
CREATE TABLE base_table (id int, ts timestamptz);
164+
CREATE VIEW a_view AS SELECT * FROM base_table;
165+
ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
166+
INSERT INTO base_table(id) VALUES(1); -- ts will receive a NULL
167+
INSERT INTO a_view(id) VALUES(2); -- ts will receive the current time
168+
</programlisting>
169+
</para>
158170
</refsect1>
159171

160172
<refsect1>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy