How to change the owner of database in PostgreSQL

If we want to alter(change) the owner, we must own the database and also be a direct or indirect member of the new owning role, and we must have the CREATEDB privilege.

How to change the owner of database in PostgreSQL

1. Check the current owner of the database. Run the below query to get owner of database.

How to get list long running processes in PostgreSQL

Why processes(sql queries) takes long time?

1. Table(object) not designed properly
2. Memory issues
3. Table Scan
4. Others

How to get list long running processes in PostgreSQL

We can get this information from pg_stat_activity object.

Following query gives logn running process, on which database it is running, start time of pid(process id) and sql text(query) the pid.

How to check list is empty or not in Python

If list contains zero elements or length of list is zero is known as empty list.

We can check whether list is empty or not using below methods

1. Declare empty list

a=[] #Empty list

type(a)

2. Check list is empty or not by using len function of list.

append vs extend in Python

append and extent both are list methods in Python. Following are the definitions of append and extend methods.

append extend
append is basically used in Python to add one element extend is used to merge two lists or insert multiple elements in one list

How to install pip

What is pip?
Pip is recommended tool to install and manage Python packages.

Pip installation:

1. Go to site.

Sort dataframe by column in R

Sort dataframe by columns in R?

We can sort the dataframe by column in R. Sort can be either ascending or descending order.

Examples:

1. Create Dataframe

df< -data.frame(x=c("A","B","K","M","L"), y=c(4,7,6,9,11), z=c(1,4,2,3,0))

How to get list of table columns in PostgreSQL

We can get list columns using describe in Oracle/SQL Server or other RDBMS. But, describe not works in PostgreSQL. We can get the list of columns in PostgreSQL using \d table_name or running query on table INFORMATION_SCHEMA.COLUMNS.

Method 1: Get list of columns of table in PostgreSQL using \d table_name

Remove Duplicates in MySQL

Duplicates are nothing but, repeated data of database objects(table,view). Find the duplicates in MySQL.

Be careful about removing duplicates. Before deleting records(duplicates) of table, its better to run the query on copy of the table.

Following table named ’emp1′ contains duplicates in the column empno and empname

Find Duplicate Rows in MySQL

Duplicates are nothing but, repeated data of database objects(table,view). We can find duplicates in different ways.

Following table named ’emp1′ contains duplicates in the column empno and empname

Apply functions in R

Apply functions are alternatives to Loops in R. In this tutorial, we are going to discuss about apply and apply family functions.

We are going to explain following apply functions with examples:

apply()
sapply()
lapply()
mapply()
vapply()
rep()
rapply()
tapply()

apply Function:

Powered by k2schools