[PATCH] Add support for INSERT ... SET syntax - Mailing list pgsql-hackers

From Suraj Kharage
Subject [PATCH] Add support for INSERT ... SET syntax
Date
Msg-id CAF1DzPXhKc15Toa06MTT7NYOAEq8Ucr=RYe5V7X2FkwGMmjD6w@mail.gmail.com
Whole thread
Responses Re: [PATCH] Add support for INSERT ... SET syntax
List 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@example.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@example.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

pgsql-hackers by date:

Previous
From: Artur Zakirov
Date:
Subject: Re: [PATCH] Add prepared_orphaned_transaction_timeout GUC
Next
From: Fujii Masao
Date:
Subject: Re: Use SIGTERM instead of SIGUSR1 for slotsync worker to exit during promotion?