Postgresql sumif

PostgreSQL does not provide a built-in SUMIF function like some other databases do. However, you can achieve similar functionality by combining the SUM and CASE statements in PostgreSQL. The SUM function in PostgreSQL calculates the sum of a given column or expression. The CASE statement allows you to perform conditional logic. Let’s say you have … Read more

How To Calculate Business Days In Power Bi

How to Calculate Business Days in Power BI In Power BI, you can calculate business days by using DAX formulas and custom tables. Here’s a step-by-step guide on how to do it: Create a custom table that defines your business days. This table should list all the valid business days and exclude weekends and holidays. … Read more

Postgresql substring after character

Query: PostgreSQL substring after character In PostgreSQL, you can substring a string after a specific character using the SUBSTRING function along with other string functions like POSITION. Let’s consider an example to understand this better. Example: — Let’s say we have a table named ’employees’ with a column ‘full_name’ — containing employee names in the … Read more

Postgresql select nolock

PostgreSQL SELECT NOLOCK In PostgreSQL, there is no direct equivalent to the NOLOCK hint found in other database systems like Microsoft SQL Server. However, you can achieve similar behavior by using the isolation level and lock type options provided by PostgreSQL. By default, PostgreSQL uses a multiversion concurrency control (MVCC) system, which allows concurrent transactions … Read more

Postgresql select last row

To select the last row in PostgreSQL, you can use the “ORDER BY” clause in combination with the “LIMIT” clause in a descending order. This will allow you to fetch the last row based on a specific column or set of columns. Let’s suppose you have a table named “employees” with columns “id”, “name”, and … Read more

Postgresql search all tables for value

To search all tables in a PostgreSQL database for a specific value, you can use the following SQL query: “`sql SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = ‘public’ AND table_catalog = ‘your_database_name’ AND table_name IN ( SELECT table_name FROM information_schema.columns WHERE table_schema = ‘public’ AND column_name ILIKE ‘%your_search_value%’ ); “` Here’s an explanation of … Read more

Postgresql rename if exists

Rename a table in PostgreSQL with IF EXISTS In PostgreSQL, you can use the ALTER TABLE command with the RENAME option to rename a table. To check if the table exists before renaming it, you can make use of the IF EXISTS clause. The following is the syntax for renaming a table: ALTER TABLE table_name … Read more