Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
sql-alterdomain.html152 linesDownload Raw Back to html
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ALTER DOMAIN</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-alterdefaultprivileges.html" title="ALTER DEFAULT PRIVILEGES" /><link rel="next" href="sql-altereventtrigger.html" title="ALTER EVENT TRIGGER" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">ALTER DOMAIN</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-alterdefaultprivileges.html" title="ALTER DEFAULT PRIVILEGES">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-altereventtrigger.html" title="ALTER EVENT TRIGGER">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-ALTERDOMAIN"><div class="titlepage"></div><a id="id-1.9.3.9.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ALTER DOMAIN</span></h2><p>ALTER DOMAIN — 3   change the definition of a domain4  </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">5ALTER DOMAIN <em class="replaceable"><code>name</code></em>6    { SET DEFAULT <em class="replaceable"><code>expression</code></em> | DROP DEFAULT }7ALTER DOMAIN <em class="replaceable"><code>name</code></em>8    { SET | DROP } NOT NULL9ALTER DOMAIN <em class="replaceable"><code>name</code></em>10    ADD <em class="replaceable"><code>domain_constraint</code></em> [ NOT VALID ]11ALTER DOMAIN <em class="replaceable"><code>name</code></em>12    DROP CONSTRAINT [ IF EXISTS ] <em class="replaceable"><code>constraint_name</code></em> [ RESTRICT | CASCADE ]13ALTER DOMAIN <em class="replaceable"><code>name</code></em>14     RENAME CONSTRAINT <em class="replaceable"><code>constraint_name</code></em> TO <em class="replaceable"><code>new_constraint_name</code></em>15ALTER DOMAIN <em class="replaceable"><code>name</code></em>16    VALIDATE CONSTRAINT <em class="replaceable"><code>constraint_name</code></em>17ALTER DOMAIN <em class="replaceable"><code>name</code></em>18    OWNER TO { <em class="replaceable"><code>new_owner</code></em> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }19ALTER DOMAIN <em class="replaceable"><code>name</code></em>20    RENAME TO <em class="replaceable"><code>new_name</code></em>21ALTER DOMAIN <em class="replaceable"><code>name</code></em>22    SET SCHEMA <em class="replaceable"><code>new_schema</code></em>23</pre></div><div class="refsect1" id="id-1.9.3.9.5"><h2>Description</h2><p>24   <code class="command">ALTER DOMAIN</code> changes the definition of an existing domain.25   There are several sub-forms:26  </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">SET</code>/<code class="literal">DROP DEFAULT</code></span></dt><dd><p>27      These forms set or remove the default value for a domain. Note28      that defaults only apply to subsequent <code class="command">INSERT</code>29      commands; they do not affect rows already in a table using the domain.30     </p></dd><dt><span class="term"><code class="literal">SET</code>/<code class="literal">DROP NOT NULL</code></span></dt><dd><p>31      These forms change whether a domain is marked to allow NULL32      values or to reject NULL values.  You can only <code class="literal">SET NOT NULL</code>33      when the columns using the domain contain no null values.34     </p></dd><dt><span class="term"><code class="literal">ADD <em class="replaceable"><code>domain_constraint</code></em> [ NOT VALID ]</code></span></dt><dd><p>35      This form adds a new constraint to a domain using the same syntax as36      <a class="link" href="sql-createdomain.html" title="CREATE DOMAIN"><code class="command">CREATE DOMAIN</code></a>.37      When a new constraint is added to a domain, all columns using that38      domain will be checked against the newly added constraint.  These39      checks can be suppressed by adding the new constraint using the40      <code class="literal">NOT VALID</code> option; the constraint can later be made41      valid using <code class="command">ALTER DOMAIN ... VALIDATE CONSTRAINT</code>.42      Newly inserted or updated rows are always checked against all43      constraints, even those marked <code class="literal">NOT VALID</code>.44      <code class="literal">NOT VALID</code> is only accepted for <code class="literal">CHECK</code> constraints.45     </p></dd><dt><span class="term"><code class="literal">DROP CONSTRAINT [ IF EXISTS ]</code></span></dt><dd><p>46      This form drops constraints on a domain.47      If <code class="literal">IF EXISTS</code> is specified and the constraint48      does not exist, no error is thrown. In this case a notice is issued instead.49     </p></dd><dt><span class="term"><code class="literal">RENAME CONSTRAINT</code></span></dt><dd><p>50      This form changes the name of a constraint on a domain.51     </p></dd><dt><span class="term"><code class="literal">VALIDATE CONSTRAINT</code></span></dt><dd><p>52      This form validates a constraint previously added as53      <code class="literal">NOT VALID</code>, that is, it verifies that all values in54      table columns of the domain type satisfy the specified constraint.55     </p></dd><dt><span class="term"><code class="literal">OWNER</code></span></dt><dd><p>56      This form changes the owner of the domain to the specified user.57     </p></dd><dt><span class="term"><code class="literal">RENAME</code></span></dt><dd><p>58      This form changes the name of the domain.59     </p></dd><dt><span class="term"><code class="literal">SET SCHEMA</code></span></dt><dd><p>60      This form changes the schema of the domain.  Any constraints61      associated with the domain are moved into the new schema as well.62     </p></dd></dl></div><p>63   You must own the domain to use <code class="command">ALTER DOMAIN</code>.64   To change the schema of a domain, you must also have65   <code class="literal">CREATE</code> privilege on the new schema.66   To alter the owner, you must be able to <code class="literal">SET ROLE</code> to the67   new owning role, and that role must have <code class="literal">CREATE</code> privilege68   on the domain's schema.  (These restrictions enforce that altering the owner69   doesn't do anything you couldn't do by dropping and recreating the domain.70   However, a superuser can alter ownership of any domain anyway.)71  </p></div><div class="refsect1" id="id-1.9.3.9.6"><h2>Parameters</h2><p>72    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>73        The name (possibly schema-qualified) of an existing domain to74        alter.75       </p></dd><dt><span class="term"><em class="replaceable"><code>domain_constraint</code></em></span></dt><dd><p>76        New domain constraint for the domain.77       </p></dd><dt><span class="term"><em class="replaceable"><code>constraint_name</code></em></span></dt><dd><p>78        Name of an existing constraint to drop or rename.79       </p></dd><dt><span class="term"><code class="literal">NOT VALID</code></span></dt><dd><p>80        Do not verify existing stored data for constraint validity.81       </p></dd><dt><span class="term"><code class="literal">CASCADE</code></span></dt><dd><p>82        Automatically drop objects that depend on the constraint,83        and in turn all objects that depend on those objects84        (see <a class="xref" href="ddl-depend.html" title="5.14. Dependency Tracking">Section 5.14</a>).85       </p></dd><dt><span class="term"><code class="literal">RESTRICT</code></span></dt><dd><p>86        Refuse to drop the constraint if there are any dependent87        objects. This is the default behavior.88       </p></dd><dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt><dd><p>89        The new name for the domain.90       </p></dd><dt><span class="term"><em class="replaceable"><code>new_constraint_name</code></em></span></dt><dd><p>91        The new name for the constraint.92       </p></dd><dt><span class="term"><em class="replaceable"><code>new_owner</code></em></span></dt><dd><p>93        The user name of the new owner of the domain.94       </p></dd><dt><span class="term"><em class="replaceable"><code>new_schema</code></em></span></dt><dd><p>95        The new schema for the domain.96       </p></dd></dl></div><p>97   </p></div><div class="refsect1" id="id-1.9.3.9.7"><h2>Notes</h2><p>98   Although <code class="command">ALTER DOMAIN ADD CONSTRAINT</code> attempts to verify99   that existing stored data satisfies the new constraint, this check is not100   bulletproof, because the command cannot <span class="quote">“<span class="quote">see</span>”</span> table rows that101   are newly inserted or updated and not yet committed.  If there is a hazard102   that concurrent operations might insert bad data, the way to proceed is to103   add the constraint using the <code class="literal">NOT VALID</code> option, commit104   that command, wait until all transactions started before that commit have105   finished, and then issue <code class="command">ALTER DOMAIN VALIDATE106   CONSTRAINT</code> to search for data violating the constraint.  This107   method is reliable because once the constraint is committed, all new108   transactions are guaranteed to enforce it against new values of the domain109   type.110  </p><p>111   Currently, <code class="command">ALTER DOMAIN ADD CONSTRAINT</code>, <code class="command">ALTER112   DOMAIN VALIDATE CONSTRAINT</code>, and <code class="command">ALTER DOMAIN SET NOT113   NULL</code> will fail if the named domain or any derived domain is used114   within a container-type column (a composite, array, or range column) in115   any table in the database.  They should eventually be improved to be able116   to verify the new constraint for such nested values.117  </p></div><div class="refsect1" id="id-1.9.3.9.8"><h2>Examples</h2><p>118   To add a <code class="literal">NOT NULL</code> constraint to a domain:119</p><pre class="programlisting">120ALTER DOMAIN zipcode SET NOT NULL;121</pre><p>122   To remove a <code class="literal">NOT NULL</code> constraint from a domain:123</p><pre class="programlisting">124ALTER DOMAIN zipcode DROP NOT NULL;125</pre><p>126  </p><p>127   To add a check constraint to a domain:128</p><pre class="programlisting">129ALTER DOMAIN zipcode ADD CONSTRAINT zipchk CHECK (char_length(VALUE) = 5);130</pre><p>131  </p><p>132   To remove a check constraint from a domain:133</p><pre class="programlisting">134ALTER DOMAIN zipcode DROP CONSTRAINT zipchk;135</pre><p>136  </p><p>137   To rename a check constraint on a domain:138</p><pre class="programlisting">139ALTER DOMAIN zipcode RENAME CONSTRAINT zipchk TO zip_check;140</pre><p>141  </p><p>142   To move the domain into a different schema:143</p><pre class="programlisting">144ALTER DOMAIN zipcode SET SCHEMA customers;145</pre></div><div class="refsect1" id="SQL-ALTERDOMAIN-COMPATIBILITY"><h2>Compatibility</h2><p>146   <code class="command">ALTER DOMAIN</code> conforms to the <acronym class="acronym">SQL</acronym>147   standard, except for the <code class="literal">OWNER</code>, <code class="literal">RENAME</code>, <code class="literal">SET SCHEMA</code>, and148   <code class="literal">VALIDATE CONSTRAINT</code> variants, which are149   <span class="productname">PostgreSQL</span> extensions.  The <code class="literal">NOT VALID</code>150   clause of the <code class="literal">ADD CONSTRAINT</code> variant is also a151   <span class="productname">PostgreSQL</span> extension.152  </p></div><div class="refsect1" id="SQL-ALTERDOMAIN-SEE-ALSO"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-createdomain.html" title="CREATE DOMAIN"><span class="refentrytitle">CREATE DOMAIN</span></a>, <a class="xref" href="sql-dropdomain.html" title="DROP DOMAIN"><span class="refentrytitle">DROP DOMAIN</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-alterdefaultprivileges.html" title="ALTER DEFAULT PRIVILEGES">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-altereventtrigger.html" title="ALTER EVENT TRIGGER">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ALTER DEFAULT PRIVILEGES </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> ALTER EVENT TRIGGER</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai