5.2. Default Values

|  5.2. Default Values  |              |                          |                  |                                   |
|:---------------------:|--------------|--------------------------|------------------|-----------------------------------|
|[Prev](ddl-basics.html)|[Up](ddl.html)|Chapter 5. Data Definition|[Home](index.html)| [Next](ddl-generated-columns.html)|

---

## 5.2. Default Values

[]()

 A column can be assigned a default value. When a new row is created and no values are specified for some of the columns, those columns will be filled with their respective default values. A data manipulation command can also request explicitly that a column be set to its default value, without having to know what that value is. (Details about data manipulation commands are in [Chapter 6](dml.html).)

[]() If no default value is declared explicitly, the default value is the null value. This usually makes sense because a null value can be considered to represent unknown data.

 In a table definition, default values are listed after the column data type. For example:

```
CREATE TABLE products (
    product_no integer,
    name text,
    price numeric DEFAULT 9.99
);

```

 The default value can be an expression, which will be evaluated whenever the default value is inserted (*not* when the table is created). A common example is for a `timestamp` column to have a default of `CURRENT_TIMESTAMP`, so that it gets set to the time of row insertion. Another common example is generating a “serial number” for each row. In PostgreSQL this is typically done by something like:

```
CREATE TABLE products (
    product_no integer DEFAULT nextval('products_product_no_seq'),
    ...
);

```

 where the `nextval()` function supplies successive values from a *sequence object* (see [Section 9.17](functions-sequence.html)). This arrangement is sufficiently common that there's a special shorthand for it:

```
CREATE TABLE products (
    product_no SERIAL,
    ...
);

```

 The `SERIAL` shorthand is discussed further in [Section 8.1.4](datatype-numeric.html#DATATYPE-SERIAL).

---

|[Prev](ddl-basics.html)|  [Up](ddl.html)  | [Next](ddl-generated-columns.html)|
|:----------------------|:----------------:|----------------------------------:|
|   5.1. Table Basics   |[Home](index.html)|       5.3. Generated Columns      |

 // \<![CDATA[ \<-- For SVG support if ('WebSocket' in window) { (function() { function refreshCSS() { var sheets = [].slice.call(document.getElementsByTagName("link")); var head = document.getElementsByTagName("head")[0]; for (var i = 0; i \< sheets.length; ++i) { var elem = sheets[i]; head.removeChild(elem); var rel = elem.rel; if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { var url = elem.href.replace(/(&|\\?)\_cacheOverride=\\d+/, ''); elem.href = url + (url.indexOf('?') \>= 0 ? '&' : '?') + '\_cacheOverride=' + (new Date().valueOf()); } head.appendChild(elem); } } var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var address = protocol + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(address); socket.onmessage = function(msg) { if (msg.data == 'reload') window.location.reload(); else if (msg.data == 'refreshcss') refreshCSS(); }; console.log('Live reload enabled.'); })(); } // ]]\>