Postagens

Mostrando postagens de setembro, 2024

Variable Preparation and Classification in Data Analysis

Data Types In the context of data analysis, data types are generally classified as quantitative and qualitative . Quantitative data represent numerical values and allow for mathematical operations, while qualitative data are categorical, grouping information into distinct categories. Quantitative : Quantitative data can be divided into discrete or continuous. Discrete : Represents countable integers, such as the number of rooms in a house, the number of bathrooms in a school, or the quantity of fruits in a basket. Continuous : Represents integers or real numbers that can take any value within a range, such as a student's score on a test, a person's weight, or the distance covered in a marathon. Qualitative : Qualitative data can be nominal or ordinal. Nominal : Do not have an order among them and classify categories without a sequential relationship, such as car brands, types of food, or times of day (morning, afternoon, night). Ordinal : Have a sequential order or ranking, ...

Bitwise Operations with PostgreSQL

Bitwise operations allow for direct manipulation of the bits that make up one or more numbers. These operations are extremely useful in scenarios where we need high performance and granular control over data, such as in binary processing or permission control systems. Some of the most common operators used in bitwise operations are AND, OR, and XOR. How Do Bitwise Operations Work? The process of applying a bitwise operator to integer numbers can be described in three simple steps: Conversion to Binary : The numbers are converted to their binary representation. Application of the Operator : The chosen operator is applied bit by bit, comparing the bits of each number. Conversion to Integer : The final result, still in binary, is converted back to decimal format. Practical Example To illustrate how these operations work, we will use the following collection of five numbers: [1, 2, 3, 4, 5]. The binary representation of these numbers is: [001, 010, 011, 100, 101]. AND Operator The AND oper...

Data Insertion with PostgreSQL Functions

The difference between a Procedure and a Function depends on how the DBMS has implemented these objects. However, PostgreSQL has long provided access to functions. Therefore, I created a function that doesn't return any value but inserts records into a table called SomeTable . You simply need to call the function to perform the insertion. CREATE OR REPLACE FUNCTION charge() RETURNS VOID AS $$ DECLARE i INTEGER := 0; BEGIN CREATE TABLE IF NOT EXISTS SomeTable(Id INTEGER GENERATED ALWAYS AS IDENTITY, Description VARCHAR, CONSTRAINT pk_SomeTable PRIMARY KEY(Id));      WHILE i < 10 LOOP           INSERT INTO SomeTable(Description) VALUES ('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');           i = i + 1;      END LOOP; END; $$ LANGUAGE plpgsql;

DROP TABLE with Foreign Keys: PostgreSQL vs. SQL Server

An interesting difference between the DBMSs PostgreSQL and SQL Server is how they handle the deletion of tables that have columns referenced by foreign keys. Consider the following scenario: The "Person" table has the "Id" column as its primary key. The "Customer" table has the "Person_Id" column as a foreign key, which references the "Id" column of the "Person" table. In PostgreSQL, when executing the command DROP TABLE Person; , the DBMS will prevent the operation due to the existing foreign key constraint. To bypass this, you can use the command DROP TABLE Person CASCADE; , which removes the "Person" table and automatically eliminates the constraints on related tables, such as "Customer", without altering the records in the "Customer" table. In SQL Server, executing the command DROP TABLE Person  will also be blocked due to the foreign key constraint. In this case, there are two possible approa...

Integration of PostgreSQL and pgAdmin Containers with Docker Compose

Imagem
To integrate PostgreSQL and pgAdmin using Docker Compose, start by creating a compose.yaml file with the following content: services:   postgres:     image: postgres     environment:       POSTGRES_PASSWORD: password   pgadmin:     image: dpage/pgadmin4     environment:       PGADMIN_DEFAULT_EMAIL: pg@ad.min       PGADMIN_DEFAULT_PASSWORD: password     ports:       - "12345:80" Save the code above into a file named compose.yaml on your computer. Then, open your terminal, navigate to the directory containing the file, and run the command docker compose up . Wait for Docker to create and start the containers. Once the containers are running, open your browser and go to http://localhost:12345 . You will be prompted to log in to pgAdmin. In the "Email Address / Username" field, enter pg@ad.min as specified in the compose.yaml file, and in the "Password" field, ent...