Setting up the Articles Table
In this step, you will create the articles
table and insert some sample data. This table will be used to demonstrate full-text search capabilities in PostgreSQL.
First, connect to the PostgreSQL database as the postgres
user using the following command in your terminal:
sudo -u postgres psql
Now, create the articles
table with the following SQL command:
CREATE TABLE articles (
id SERIAL PRIMARY KEY,
title VARCHAR(255),
content TEXT
);
This command creates a table named articles
with three columns: id
, title
, and content
. The id
column is an auto-incrementing primary key.
Next, insert some sample data into the articles
table:
INSERT INTO articles (title, content) VALUES
('PostgreSQL Tutorial', 'This is a comprehensive tutorial on PostgreSQL.'),
('Full Text Search in PostgreSQL', 'Learn how to implement full text search using TSVECTOR in PostgreSQL.'),
('PostgreSQL Performance Tuning', 'Tips and tricks to improve the performance of your PostgreSQL database.');
This command inserts three rows into the articles
table, each with a different title and content.
You can verify the data has been inserted correctly by running the following query:
SELECT * FROM articles;
You should see the three rows you just inserted.
id | title | content
----+----------------------------------+-----------------------------------------------------------------------
1 | PostgreSQL Tutorial | This is a comprehensive tutorial on PostgreSQL.
2 | Full Text Search in PostgreSQL | Learn how to implement full text search using TSVECTOR in PostgreSQL.
3 | PostgreSQL Performance Tuning | Tips and tricks to improve the performance of your PostgreSQL database.
(3 rows)