| From: | Suraj Kharage <suraj(dot)kharage(at)enterprisedb(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | [PATCH] Add support for INSERT ... SET syntax |
| Date: | 2026-03-30 11:04:27 |
| Message-ID: | CAF1DzPXhKc15Toa06MTT7NYOAEq8Ucr=RYe5V7X2FkwGMmjD6w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
I would like to propose adding support for an alternative INSERT syntax
that uses named column assignments via a SET clause. This provides a more
convenient and readable way to write inserts, particularly when only
specific columns need values.
Currently, PostgreSQL requires INSERT statements to separate the column
list from the values:
INSERT INTO users (name, email, status) VALUES ('Alice', '
alice(at)example(dot)com', 'active');
For inserts with many columns or where only a subset of columns are
specified, the proposed SET syntax offers better readability by keeping
column names adjacent to their values:
INSERT INTO users SET name='Alice', email='alice(at)example(dot)com',
status='active';
Proposed Syntax:
INSERT INTO table_name
SET (column1=value1, column2=value2, ...), (, ...)
[ ON CONFLICT ... ]
[ RETURNING ... ];
Below INSERT features are supported:
- DEFAULT keyword: SET col=DEFAULT
- Expressions and functions: SET col=expr, col2=function(...)
- Subqueries: SET col=(SELECT ...)
- RETURNING clause
- ON CONFLICT DO UPDATE/NOTHING
- OVERRIDING SYSTEM VALUE
- Multi-row syntax: SET (col1=val1, col2=val2), (col1=val3, col2=val4)
Columns not mentioned receive their default values or NULL, consistent with
standard INSERT behavior.
I've attached the patch. Looking forward to your feedback.
--
Thanks & Regards,
Suraj kharage,
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Add-support-for-INSERT-.-SET-syntax.patch | application/octet-stream | 30.1 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2026-03-30 11:09:20 | Re: Use SIGTERM instead of SIGUSR1 for slotsync worker to exit during promotion? |
| Previous Message | Artur Zakirov | 2026-03-30 10:44:23 | Re: [PATCH] Add prepared_orphaned_transaction_timeout GUC |