Re: SET syntax in INSERT - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: SET syntax in INSERT
Date
Msg-id 4A942B27.70007@enterprisedb.com
Whole thread Raw
In response to Re: SET syntax in INSERT  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: SET syntax in INSERT  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-hackers
Pavel Stehule wrote:
> 2009/8/25 Rob Wultsch <wultsch@gmail.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'
AScol6,      '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


pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: SET syntax in INSERT
Next
From: Jaime Casanova
Date:
Subject: Re: Feature / Enhancement request.