Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 07e7430

Browse files
committed
Update release notes to show how to upgrade a database to use the new
early binding for nextval() calls in default clauses.
1 parent 6a17577 commit 07e7430

File tree

1 file changed

+62
-10
lines changed

1 file changed

+62
-10
lines changed

doc/src/sgml/release.sgml

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.381 2005/10/02 23:50:06 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.382 2005/10/03 01:57:59 momjian Exp $
33

44
Typical markup:
55

@@ -262,6 +262,21 @@ pg_[A-Za-z0-9_] <application>
262262

263263
<itemizedlist>
264264

265+
<listitem>
266+
<para>
267+
<varname>Add proper sequence function dependencies (Tom)
268+
</para>
269+
<para>
270+
In previous releases, <function>nextval()</>,
271+
<function>currval</>, and <function>setval()</> recorded
272+
sequence names as simple text strings, meaning that renaming or
273+
dropping a sequence used in a <command>DEFAULT</> made the
274+
clause invalid. This release stores all newly-created sequence
275+
function arguments using internal oids, allowing them to handle
276+
sequence renaming, and adding dependency information that
277+
</para>
278+
</listitem>
279+
265280
<listitem>
266281
<para>
267282
<varname>add_missing_from</> is now false by default (Neil)
@@ -398,16 +413,53 @@ pg_[A-Za-z0-9_] <application>
398413
</para>
399414
<para>
400415
When an expression like <literal>nextval('myseq')</> appears in a
401-
column default expression or view, the referenced sequence (here
402-
<literal>myseq</>) is now looked up immediately, and its pg_class
403-
OID is placed in the stored expression. This representation will
404-
survive renaming of the referenced sequence, as well as changes in
405-
schema search paths. The system also understands that the sequence
406-
reference represents a dependency, so the sequence cannot be dropped
407-
without dropping the referencing object. To get the old behavior of
408-
run-time lookup of the sequence by name, cast the argument to
409-
<type>text</>, for example <literal>nextval('myseq'::text)</>.
416+
column <command>DEFAULT</> expression or view, the referenced
417+
sequence (here <literal>myseq</>) is now looked up immediately,
418+
and its pg_class OID is placed in the stored expression. This
419+
representation will survive renaming of the referenced sequence,
420+
as well as changes in schema search paths. The system also
421+
understands that the sequence reference represents a dependency,
422+
so the sequence cannot be dropped without dropping the
423+
referencing object. Previous releases stored this information as
424+
a simple text string, with none of the benefits outlined above.
425+
To get the old text-based behavior of run-time lookup of the
426+
sequence name, cast the argument to <type>text</>, for example
427+
<literal>nextval('myseq'::text)</>.
410428
</para>
429+
<para>
430+
Pre-8.1 schemas loaded into 8.1 will use the previous, text-based
431+
representation and therefore will not have these protections.
432+
However, it is possible to upgrade a database to the newer
433+
OID-based arguments. First, save this query into a file, such as
434+
<filename>fixseq.sql</>:
435+
<programlisting>
436+
SELECT 'ALTER TABLE ' ||
437+
pg_catalog.quote_ident(n.nspname) || '.' ||
438+
pg_catalog.quote_ident(c.relname) ||
439+
' ALTER COLUMN ' || pg_catalog.quote_ident(a.attname) ||
440+
' SET DEFAULT ' ||
441+
regexp_replace(d.adsrc, '(nextval\\(''[^'']*'')::text', '\\1', 'g') ||
442+
';'
443+
FROM pg_namespace n, pg_class c, pg_attribute a, pg_attrdef d
444+
WHERE n.oid = c.relnamespace AND
445+
c.oid = a.attrelid AND
446+
a.attrelid = d.adrelid AND
447+
a.attnum = d.adnum AND
448+
d.adsrc ~ '.*nextval\\(''[^'']*''::text';
449+
</programlisting>
450+
Next, run the query against a database to find what
451+
adjustments are required, like this for database <literal>db1</>:
452+
<programlisting>
453+
psql -aT -f fixseq.sql db1
454+
</programlisting>
455+
This will show the <command>ALTER TABLE</> commands needed to
456+
convert the database to the newer OID-based representation.
457+
Finally, run this to update the database:
458+
<programlisting>
459+
psql -aT -f fixseq.sql db1 | psql -e db1
460+
</programlisting>
461+
This process should be done for each database loaded with pre-8.1
462+
schemas.
411463
</listitem>
412464

413465
<listitem>

0 commit comments

Comments
 (0)