Python Psycopg2 - Concatenate columns to new column Last Updated : 17 Oct, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we are going to see how to concatenate multiple columns of a table in a PostgreSQL database into one column. To concatenate two or more columns into one, PostgreSQL provides us with the concat() function. Table for demonstration: In the below code, first, a connection is formed to the PostgreSQL database 'geeks' by using the connect() method. after connecting to the database SQL update command is executed using the execute() command, which helps us create a new column called 'empno_name', after creating the column, we use the update command to populate the new column with the concatenated values after concatenating columns 'empno' and 'ename' from the above table. The third SQL command 'select employee from empno_name;' is used to view the concatenated column. Below is the implementation: Python3 import psycopg2 conn = psycopg2.connect( database="geeks", user='postgres', password='root', host='localhost', port='5432' ) conn.autocommit = True cursor = conn.cursor() # adding an extra column sql ='''alter table employee add column empno_name varchar(30);''' cursor.execute(sql) # updating the new tables with values sql1 = '''UPDATE employee SET empno_name = concat(empno, ename);''' cursor.execute(sql1) # printing out the concatenated column sql2 = '''select empno_name from employee;''' cursor.execute(sql2) results = cursor.fetchall() for i in results: print(i) conn.commit() conn.close() Output: ('1216755raj',) ('1216756sarah',) ('1216757rishi',) ('1216758radha',) ('1216759gowtam',) ('1216754rahul',) ('191351divit',) ('191352rhea',)PostgreSQL Output: Comment More infoAdvertise with us Next Article Python Psycopg2 - Concatenate columns to new column isitapol2002 Follow Improve Article Tags : Python Python PostgreSQL Python Pyscopg2 Practice Tags : python Similar Reads Get Column name and Column type with Python psycopg2 When working with PostgreSQL databases in Python, one common task is to retrieve metadata about database tables, such as column names and their types. This information can be crucial for dynamically generating queries, validating data, or understanding the structure of our database. The psycopg2 lib 4 min read Concatenate two columns of Pandas dataframe Let's discuss how to Concatenate two columns of dataframe in pandas python. We can do this by using the following functions : concat() append() join() Example 1 : Using the concat() method. Python3 1== # importing the module import pandas as pd # creating 2 DataFrames location = pd.DataFrame({'area' 2 min read Convert Column To Comma Separated List In Python A comma-separated list in Python is a sequence of values or elements separated by commas. Pandas is a Python package that offers various data structures and operations for manipulating numerical data and time series. Convert Pandas Columns to Comma Separated List Using .tolist()This article will exp 4 min read How to Concatenate Column Values of a MySQL Table Using Python? Prerequisite: Python: MySQL Create Table In this article, we show how to concatenate column values of a MySQL table using Python. We use various data types in SQL Server to define data in a particular column appropriately. We might have requirements to concatenate data from multiple columns into a s 2 min read Perform Insert Operations with psycopg2 in Python psycopg2 is a widely used Python library designed to facilitate communication with PostgreSQL databases, offering a robust and efficient way to perform various database operations. It is a powerful and flexible connector, which allows Python applications to execute SQL commands and handle data seaml 9 min read How to Convert Dataframe column into an index in Python-Pandas? Pandas provide a convenient way to handle data and its transformation. Let's see how can we convert a data frame column to row name or index in Pandas. Create a dataframe first with dict of lists.  Python3 # importing pandas as pd import pandas as pd # Creating a dict of lists data = {'Name':["Akas 2 min read Join two text columns into a single column in Pandas Let's see the different methods to join two text columns into a single column. Method #1: Using cat() function We can also use different separators during join. e.g. -, _, " " etc. Python3 1== # importing pandas import pandas as pd df = pd.DataFrame({'Last': ['Gaitonde', 'Singh', 'Mathur'], 'First': 2 min read Get column names from CSV using Python CSV (Comma Separated Values) files store tabular data as plain text, with values separated by commas. They are widely used in data analysis, machine learning and statistical modeling. In Python, you can work with CSV files using built-in libraries like csv or higher-level libraries like pandas. In t 2 min read Split a text column into two columns in Pandas DataFrame Let's see how to split a text column into two columns in Pandas DataFrame. Method #1 : Using Series.str.split() functions. Split Name column into two different columns. By default splitting is done on the basis of single space by str.split() function. Python3 # import Pandas as pd import pandas as p 3 min read Like