PostgreSQL - Select Into Last Updated : 28 Aug, 2020 Comments Improve Suggest changes Like Article Like Report In PostgreSQL, the select into statement to select data from the database and assign it to a variable. Syntax: select select_list into variable_name from table_expression; In this syntax, one can place the variable after the into keyword. The select into statement will assign the data returned by the select clause to the variable. Besides selecting data from a table, one can use other clauses of the select statement such as join, group by, and having. Example 1: To demonstrate the use of select into statement we will use the sample database, ie, dvdrental. do $$ declare actor_count integer; begin -- select the number of actors from the actor table select count(*) into actor_count from actor; -- show the number of actors raise notice 'The number of actors: %', actor_count; end; $$; Output: In the above example we did the following: First, declare a variable called actor_count that stores the number of actors from the actor table.Second, use the select into statement to assign the number of actors to the actor_count.Finally, display a message that shows the value of the actor_count variable using the raise notice statement. Example 2: Here we will use the select into statement to assign the value of total number of films in the database to a variable film_count using the below statement: do $$ declare film_count integer; begin -- select the number of films from the actor table select count(*) into film_count from film; -- show the number of films raise notice 'The number of films: %', film_count; end; $$; Output: Comment More infoAdvertise with us Next Article PostgreSQL - Select Into R RajuKumar19 Follow Improve Article Tags : PostgreSQL postgreSQL-managing-table postgreSQL-basics Similar Reads PostgreSQL - SELECT INTO The PostgreSQL SELECT INTO statement allows users to create a new table directly from the result set of a query. This command is ideal for duplicating or organizing data from an existing table into a new one for further analysis. SELECT INTO does not return data to the client but saves it in a new t 4 min read PostgreSQL - SELECT PostgreSQL SELECT statement is an command for retrieving data from tables within a PostgreSQL database. It enables users to specify which columns to fetch and apply filters using the WHERE clause for targeted results.In this article, We will learn about the PostgreSQL SELECT in detail by understandi 3 min read PostgreSQL - IF Statement PostgreSQL IF statement is an essential tool for implementing conditional logic within SQL queries and stored procedures. It allows developers to execute different actions based on specific conditions and enhances the flexibility of database operations. In this article, we will explore various Postg 5 min read PostgreSQL - INSERT PostgreSQL INSERT statement is one of the fundamental SQL commands used to add new rows to a specified table within a PostgreSQL database. This command allows users to insert data efficiently, whether for a single record or multiple records at once. With the PostgreSQL INSERT INTO clause, we can spe 4 min read PostgreSQL - Loop Statement The LOOP statement in PL/pgSQL is used to create an unconditional loop that executes a block of code repeatedly until a RETURN or EXIT statement terminates it. This article will help you understand the syntax and usage of the LOOP statement, and provide examples to display its application.Let us get 3 min read PostgreSQL REVERSE() Function The REVERSE() function in PostgreSQL is a simple yet powerful tool used to reverse the order of characters in a given string. It takes one input which is a string and returns the characters in reverse order. This function is helpful when you need to transform data, run tests or validate information. 4 min read PostgreSQL - IN operator The IN operator in PostgreSQL is a powerful and efficient tool used to filter records based on a predefined set of values. When used with the WHERE clause, it simplifies SQL queries and enhances readability, making it a key component of SQL query optimization for data retrieval and database manipula 4 min read PostgreSQL - GRANT In PostgreSQL, the GRANT statement is a powerful tool used to assign privileges to a role, allowing it to alter database objects like tables, views, functions, and more. Here we will learn about the syntax and application of the GRANT statement, with examples to illustrate its usage in PostgreSQL.Sy 3 min read PostgreSQL - CASE Statement In PostgreSQL, CASE statements provide a way to implement conditional logic within SQL queries. Using these statements effectively can help streamline database functions, optimize query performance, and provide targeted outputs. This guide will break down the types of CASE statements available in Po 4 min read PostgreSQL - RIGHT Function The PostgreSQL RIGHT() function, allows you to extract a specified number of characters from the right side of a string. This function can be incredibly useful for various text-processing tasks.Let us get a better understanding of the RIGHT Function in PostgreSQL from this article.SyntaxRIGHT(string 2 min read Like