Loading topic
INSERT statements, know what a primary key and a column default are, and can run SQL in psql or another PostgreSQL client. The examples use the tasks table below. All of them work on any supported PostgreSQL version.6 min readUPDATE ... WHERE, you know what a primary key and a column default are, and you can run statements in psql or another PostgreSQL client. The earlier chapters introduced RETURNING on INSERT. Here we look at what it does on UPDATE.6 min readSELECT, INSERT, UPDATE and DELETE statements. It also assumes you know what primary keys and column defaults are, and that you can run SQL in psql or another PostgreSQL client. Earlier chapters introduced the RETURNING clause. Here you apply it to6 min readINSERT, UPDATE and DELETE in psql, and that you have written basic application code that talks to PostgreSQL. It also assumes you have the tasks table from earlier chapters. The examples use Python with psycopg 3 and Node.js with pg. The same ideas apply 6 min readINSERT, UPDATE and DELETE statements, and that you know what a common table expression (CTE) is, meaning a named subquery introduced with WITH. It also assumes you have seen RETURNING on a single statement. Here you will connect several statements in5 min readINSERT ... ON CONFLICT statements and know how RETURNING works on plain INSERT, UPDATE and DELETE. It also assumes you can run SQL in psql or another PostgreSQL client. The examples use the tasks table from earlier chapters. The MERGE example ne6 min readUPDATE and DELETE can join to other tables while they change rows. PostgreSQL does this with UPDATE ... FROM and DELETE ... USING. In both statements the RETURNING list can read columns from those joined tables as well as from the target table. This chapter shows how that works, what it re6 min readRETURNING list. It also assumes you know column defaults, identity columns and the idea of a row-level trigger. Here you will learn which version of a row RETURNING reports when defaults, generated columns and triggers all5 min readINSERT, UPDATE, DELETE and ON CONFLICT with RETURNING. It also assumes you know the basic shape of MERGE. You need PostgreSQL 17 or later to run the examples. On PostgreSQL 16 and earlier, MERGE does not accept a RETURNING cl6 min readRETURNING read both the old and the new version of a row in the same statement. This chapter covers the syntax, what each statement puts in old and new, and the patterns this makes simple: change detection, audit rows and upsert diagnosis.6 min readINSERT, UPDATE, DELETE ... RETURNING and can run statements in psql or another client. It also assumes you have seen ON CONFLICT, data-modifying CTEs and triggers in earlier chapters. All examples use the tasks table from earlier in the tu6 min read