aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-02-09 11:43:48 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-02-09 11:43:48 -0500
commit3a1f8cdfa90443117049c601364009b71eaad3d1 (patch)
tree8966b8d82455d5df36e17dfbe745635e548f6c24 /doc/src
parent0343a59d119de3fb835234fa34fbcd697b9335db (diff)
downloadpostgresql-3a1f8cdfa90443117049c601364009b71eaad3d1.tar.gz
postgresql-3a1f8cdfa90443117049c601364009b71eaad3d1.zip
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.
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/alter_view.sgml14
1 files changed, 13 insertions, 1 deletions
diff --git a/doc/src/sgml/ref/alter_view.sgml b/doc/src/sgml/ref/alter_view.sgml
index 0e2b140241e..55674c650a9 100644
--- a/doc/src/sgml/ref/alter_view.sgml
+++ b/doc/src/sgml/ref/alter_view.sgml
@@ -154,7 +154,19 @@ ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RESET
<literal>bar</literal>:
<programlisting>
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>