In the above statement, we create a table name as emp_info using create table statement.We are separating the name of the columns by using the comma.In the above syntax where create the table is a keyword, table name means new table name that we need to develop, and column names 1 and 2 specified column name in the table with data type and operator.Syntax: create table table name ( column name_1 data type (null | not null), column name_2 data type ( null | not null),……………. So we use the following statement to create a table. Note that, the returning clause is an extension to the INSERT statement provided by PostgreSQL over the SQL standard.Let’s create a table to perform insert into a statement using a create table statement. In this tutorial, we learned how to insert single or multiple records into the table along with the RETURNING clause. RETURNING * Code language: PostgreSQL SQL dialect and PL/pgSQL ( pgsql ) Returning All Column ValuesĪs you can see, using the * symbol will return all column values for all records. INSERT INTO employees ( name, department, salary, hire_date) However, if you want to see all column values, use the asterisk (*) sign as shown below. Returning Column ValuesĪs you can see, all the values are printed. Here, we are returning the values of all columns. RETURNING id, name, department, salary, hire_date Code language: PostgreSQL SQL dialect and PL/pgSQL ( pgsql ) ![]() Let’s now see an example of the RETURNING clause. RETURNING col2 as ID Code language: PostgreSQL SQL dialect and PL/pgSQL ( pgsql ) Examples of the RETURNING Clause You can also use the alias for the returning column value using the following syntax- INSERT INTO table(col2,col3) VALUES If you want to return the whole row, you can use the * symbol after the RETURNING keyword. Here, the query will return the values of col2 after completing the insertion operation. RETURNING col2 Code language: PostgreSQL SQL dialect and PL/pgSQL ( pgsql ) ![]() You can return the inserted row names, ids or entire rows. The INSERT statement also provides us with the optional clause RETURNING which returns the information about the inserted row/rows. RETURNING Clause in PostgreSQL INSERT Statement ( 'Sarah Lee', 'Finance', 65000.00, '') Code language: PostgreSQL SQL dialect and PL/pgSQL ( pgsql ) Insert Multiple RecordsĪs you can see, now we got 0 3, which means three records have been inserted into the table. If you are a beginner and remember these things, you are good to go! In case of multiple rows, each row must be separated by a comma too.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |