PostgreSQL Add Primary Key: Existing Table, Composite Key and Drop

PostgreSQL add primary key with ALTER TABLE and the customers_pkey index shown in psql

Your customers table went live without a primary key, and now you want one. The statement is short. The data in the column decides whether it works. Quick answer: the PostgreSQL add primary key command is ALTER TABLE customers ADD PRIMARY KEY (customer_id);. PostgreSQL builds a unique index named customers_pkey and marks the column NOT … Read more >>

Postgresql REGEXP_REPLACE Function

Postgresql regexp_replace special characters

In this PostgreSQL tutorial, we will learn about “Postgresql regexp_replace” and cover the following topics. Postgresql regexp_replace In Postgresql, the REGEXP_REPLACE function replaces substrings that match a POSIX regular expression with a new substring. The syntax of regexp_replace is given below. Where the source is a string where the replacement will take. pattern: The pattern … Read more >>

Postgresql generate_series Examples

Postgresql generate_series of months

In this PostgreSQL tutorial, we will learn about “Postgresql generate_series” which helps in generating series of numbers, dates, months and row numbers, etc. Postgresql generate_series In Postgresql, we use the generate_series() function to generate series of numbers. Use the below command to generate series of numbers: Syntax: Postgresql generate_series function accepts three parameters: Note: The … Read more >>

PostgreSQL ADD COLUMN

In this PostgreSQL tutorial, we will discuss, about PostgreSQL ADD COLUMN statement with 17 examples to add one or more columns to an existing table. PostgreSQL ADD COLUMN To add a new column to an existing table in PostgreSQL, you can use the ALTER TABLE ADD COLUMN statement. The syntax is as follows: In the above syntax, NOTE … Read more >>

PostgreSQL vs SQL Server

PostgresSQL vs SQL Server

As a Project Manager, I was confused about which relational database management system to choose for my upcoming project, PostgreSQL or SQL Server. Both are powerful enough in their feature, but both serve different purposes. Still, I have to consider my project’s cost and technical requirements. Here, I have shared a detailed comparison of PostgreSQL … Read more >>

How to Create View in PostgreSQL

Create View in Postgres using Multiple Tables

In this PostgreSQL tutorial, I will show you how to create a view in Postgres. You will learn “what is the view?” and the syntax for creating the view and its execution process. How to Create View in PostgreSQL Before diving deep into the topic, let me understand what views are. What Are PostgreSQL Views? … Read more >>

Postgresql listen_addresses

Postgresql listen_addresses example

In this PostgreSQL tutorial, we will learn about “PostgreSQL listen_addresses” and how to connect to PostgreSQL from any IP address across different environments, using various examples. Postgresql listen_addresses Before beginning, we need to know “What is listen_address?” listen_addresses is found in the section of the PostgreSQL.conf file. It enables the database server to listen for incoming connections on the specified IP … Read more >>

PostgreSQL date between two dates

Postgresql date between two dates

In this PostgreSQL tutorial, I’ll guide you through multiple approaches to filtering data between two dates in PostgreSQL, complete with practical examples and performance considerations. PostgreSQL date between two dates Why Date Range Filtering Matters in PostgreSQL Before diving into the syntax, let’s understand why effective date filtering is crucial: Now, let’s explore the various … Read more >>

PostgreSQL TO_TIMESTAMP

PostgreSQL TO_TIMESTAMP format

In this PostgreSQL tutorial, we will discuss the PostgreSQL TO_TIMESTAMP() function, which converts a string into a timestamp type value based on a specified format, with 11 real-time examples. PostgreSQL TO_TIMESTAMP PostgreSQL provides several data type formatting functions, which serve as a comprehensive set of tools to convert various data type values (such as date-time/timestamp, integer, numeric, and floating-point) into formatted strings … Read more >>

PostgreSQL DATE Functions Examples

PostgreSQL Date Functions Manipulation DATE_PART YEAR

In this PostgreSQL tutorial, we will learn about PostgreSQL DATE Functions Examples and know how to extract specific parts of the dates, manipulate the dates, perform arithmetic operations on dates, and convert dates or times to different time zone. PostgreSQL DATE Functions Examples Let us discuss various examples one by one in detail. Example 1: … Read more >>