Re: SET syntax in INSERT

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Rob Wultsch <wultsch(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: SET syntax in INSERT
Date: 2009-08-25 18:19:19
Message-ID: 4A942B27.70007@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Pavel Stehule wrote:
> 2009/8/25 Rob Wultsch <wultsch(at)gmail(dot)com>:
>> Given the recent discussion of "DELETE syntax on JOINS" I thought it
>> might be interesting to bring a bit MySQL syntax that is in somewhat
>> widespread use, generally create somewhat cleaner code and I imagine
>> would not break much if implemented.
>>
>> MySQL allows INSERTs of the form:
>>
>> INSERT INTO t SET
>> col1='val1',
>> col2='va21',
>> col3='val3',
>> col4='val4',
>> col5='val5',
>> col6='val6',
>> col7='val7',
>> col8='val8',
>> col9='val9',
>> col10='val10',
>> col11='val11',
>> col12='val12',
>> col13='val13',
>> col14='val14',
>> col15='val15';
>>
>> Which I think sometimes compares very favorably
>> INSERT INTO t
>> (col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13,col14,col15)
>> VALUES
>> ('val1','val2','val3','val4','val5','val6','val7','val8','val9','val10','val11','val12','val13','val14','val15')
>>
>> Probably a pipe dream...
>
> -1 PostgreSQL isn't MySQL!

Agreed, I don't see us implementing that.

I do understand the point, though - it's much easier to edit and debug
long statements when the value is close to the column name. I find that
the INSERT .. SELECT makes that a lot nicer:

INSERT INTO t
(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13,col14,col15)
SELECT 'val1' AS col1,
'val2' AS col2,
'val3' AS col3,
'val4' AS col4,
'val5' AS col5,
'val6' AS col6,
'val7' AS col7,
'val8' AS col8,
'val9' AS col9,
'val10' AS col10,
'val11' AS col11,
'val12' AS col12,
'val13' AS col13,
'val14' AS col14,
'val15' AS col15;

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rob Wultsch 2009-08-25 18:19:50 Re: SET syntax in INSERT
Previous Message Jaime Casanova 2009-08-25 18:12:04 Re: Feature / Enhancement request.