CREATETABLEtasks(
id SERIALPRIMARYKEY,
title VARCHAR(200)NOTNULL,
status VARCHAR(20)DEFAULT'pending',
priority INTEGERDEFAULT0,
created_at TIMESTAMPDEFAULTCURRENT_TIMESTAMP);
Output
-- Omitting status, priority, or created_at uses defaults
Note DEFAULT applies only when the column is omitted from INSERT. Explicitly inserting NULL overrides the default with NULL (unless NOT NULL is also set). You can use expressions like CURRENT_TIMESTAMP as defaults.
Frequently asked questions
How does React handle default value?
This task is covered in 2 stacks on this page: React, SQL. The "Default Prop Values" snippet in React uses `function Component({ propA = defaultValue }) { ... }`.
Which code does the React example use?
The "Default Prop Values" snippet uses `function Component({ propA = defaultValue }) { ... }`, from the Components section of the React cheat sheet.
Which stacks cover "default value" on this page?
React, SQL. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Default Prop Values": Use default parameter values in the destructuring rather than the legacy defaultProps static property, which is deprecated in React 19.