CHARACTER
Example
Section titled “Example”CREATE TABLE Employees ( ID int, Name CHARACTER(30), Age int);
INSERT INTO Employees (ID, Name, Age)VALUES (1, 'John Doe', 30);
SELECT * FROM Employees;Output
Section titled “Output”+------+------------------+-----+| ID | Name | Age |+------+------------------+-----+| 1 | John Doe | 30 |+------+------------------+-----+Explanation
Section titled “Explanation”In this example, a table named ‘Employees’ is created with three columns - ‘ID’ as an integer, ‘Name’ as character data type of length 30, and ‘Age’ as an integer. Then, a new row is inserted into the ‘Employees’ table with ‘ID’ as 1, ‘Name’ as ‘John Doe’ and ‘Age’ as 30. Finally, all the records from the ‘Employees’ table are selected. The output shows the records retrieved from the table.
Example
Section titled “Example”CREATE TABLE Employees ( ID SERIAL PRIMARY KEY, NAME CHARACTER(15));
INSERT INTO Employees(NAME) VALUES ('Doerayme');Output
Section titled “Output”INSERT 0 1Explanation
Section titled “Explanation”This example demonstrates the application of the CHARACTER data type in PostgreSQL. The CREATE TABLE statement establishes a new table named ‘Employees’ with columns ‘ID’ and ‘NAME’. The ‘ID’ column is set as the primary key with sequential integers utilizing the SERIAL keyword. The ‘NAME’ column is defined by the CHARACTER(15) data type, which accommodates a string of characters up to 15 in length. With the INSERT INTO command, a row is populated with ‘Doerayme’ inserted into the ‘NAME’ column.