Database Reference
In-Depth Information
emp_name | Bob
salary | 1300
-[ RECORD 2 ]---
emp_name | Fred
salary | 750
-[ RECORD 3 ]---
emp_name | frank
salary | 100
-[ RECORD 4 ]---
emp_name | ARNOLD
salary | 80
After fixing the existing mixed-case emp_names , we can make sure that all
emp_names will be in uppercase in the future by adding a constraint:
postgres=# update salaries set emp_name =
upper(emp_name) where not emp_name =
upper(emp_name);
UPDATE 3
postgres=# alter table salaries add constraint
emp_name_must_be_uppercasepostgres-# CHECK
(emp_name = upper(emp_name));
ALTER TABLE
If this behavior is needed in more places, it would make sense to define a new type
- say u_text , which is always stored as uppercase. You will learn more about this
approach in the chapter about defining user types.
Search WWH ::




Custom Search