PostgreSQL dml queries

  • Post comments:0 Comments
  • Reading time:4 mins read
  • Post category:SQL

PostgreSQL DML (Data manipulation language ) statements to access and manipulate data in existing schema objects. These statements do not implicitly commit the current transaction. Some of the important data manipulation language statements are:

A SELECT statement is a limited form of DML statement in that it can only access data in the database. It cannot manipulate data stored in the database, although it can manipulate the accessed data before returning the results of the query.

In the postgreSQL, you can enter a DML statement after the sql prompt.

The effect of a DML statement is not permanent until you commit the transaction that includes it. A transaction is a sequence of SQL statements that Oracle Database treats as a unit (it can be a single DML statement). Until a transaction is committed, it can be rolled back (undone). For more information about transactions,

PostgreSQL DML includes

INSERT: insert a record into the table.
SELECT: Retrieves the records from the table.
UPDATE: update the existing record with the new values.
DELETE: delete a record from the table.
UPSERT: upsert in nothing but merge. The idea is that when you insert a new row into the table, PostgreSQL will update the row if it already exists, otherwise, PostgreSQL inserts the new row.

PostgreSQL insert query

PostgreSQL select query

PostgreSQL update query

PostgreSQL delete query

PostgreSQL upsert

syntax

INSERT INTO table_name(column_list) VALUES(value_list)
ON CONFLICT target action;

The target can be:

(column_name) – a column name.

ON CONSTRAINT constraint_name – where the constraint name could be a name of the UNIQUE constraint.
WHERE predicate – a WHERE clause with a predicate

The action can be:

DO NOTHING – means do nothing if the row already exists in the table.
DO UPDATE SET column_1 = value_1, .. WHERE condition – update some fields in the table.


Words from postgreshelp

Thank you for giving your valuable time to read the above information. I hope the content served your purpose in reaching out the blog.
Suggestions for improvement of the blog are highly appreciable. Please contact us for any information/suggestion/feedback.

If you want to be updated with all our articles

please follow us on Facebook Twitter
Please subscribe to our newsletter.

 

Leave a Reply