Re: [GENERAL] referencing other INSERT VALUES columns inside the insert

2015-11-17 Thread Jim Nasby
On 11/17/15 8:53 AM, Geoff Winkless wrote: It takes the column's default value, since it's not explicit in the first INSERT. Not sure if it would help or not, but you can use pg_get_expr(adbin, adrelid) against pg_attrdef to get the default for a column. That would let you dynamically insert

Re: [GENERAL] referencing other INSERT VALUES columns inside the insert

2015-11-17 Thread Geoff Winkless
On 17 November 2015 at 14:31, Adrian Klaver wrote: > On 11/17/2015 01:14 AM, Geoff Winkless wrote: > >> INSERT INTO test (c1, c2) VALUES (3, 7); UPDATE test SET c4=c1*c2 WHERE >> c1=3; UPDATE test SET c5=c4*c3 WHERE c1=3; >> > > Could the above not be shortened to?: > > INSERT INTO test (c1, c2)

Re: [GENERAL] referencing other INSERT VALUES columns inside the insert

2015-11-17 Thread Adrian Klaver
On 11/17/2015 01:14 AM, Geoff Winkless wrote: On 16 November 2015 at 15:48, David G. Johnston mailto:david.g.johns...@gmail.com>>wrote: ​You don't need WITH to accomplish this... INSERT INTO test (c1, c2, c3) SELECT c1, c2, c1 * c2 FROM ( VALUES (3, 7) ) vals (c1, c2); Davi

Re: [GENERAL] referencing other INSERT VALUES columns inside the insert

2015-11-17 Thread Adrian Klaver
On 11/17/2015 01:14 AM, Geoff Winkless wrote: On 16 November 2015 at 15:48, David G. Johnston mailto:david.g.johns...@gmail.com>>wrote: ​You don't need WITH to accomplish this... INSERT INTO test (c1, c2, c3) SELECT c1, c2, c1 * c2 FROM ( VALUES (3, 7) ) vals (c1, c2); Davi

Re: [GENERAL] referencing other INSERT VALUES columns inside the insert

2015-11-17 Thread Geoff Winkless
On 16 November 2015 at 15:48, David G. Johnston wrote: > ​You don't need WITH to accomplish this... > > INSERT INTO test (c1, c2, c3) > SELECT c1, c2, c1 * c2 > FROM ( VALUES (3, 7) ) vals (c1, c2); > > David J. > > ​Oh I see, so it's the ability to use VALUES in place of a SELECT, really. I supp

Re: [GENERAL] referencing other INSERT VALUES columns inside the insert

2015-11-16 Thread David G. Johnston
On Mon, Nov 16, 2015 at 4:06 AM, Geoff Winkless wrote: > On 16 November 2015 at 10:55, Albe Laurenz > wrote: > >> What about something along these lines: >> >> INSERT INTO test (c1, c2, c3) >>(WITH fixed(x1, x2) AS (VALUES (3, 7)) >> SELECT x1, x2, x1 * x2 FROM fixed); >> > > ​Genius! >

Re: [GENERAL] referencing other INSERT VALUES columns inside the insert

2015-11-16 Thread Geoff Winkless
On 16 November 2015 at 10:55, Albe Laurenz wrote: > What about something along these lines: > > INSERT INTO test (c1, c2, c3) >(WITH fixed(x1, x2) AS (VALUES (3, 7)) > SELECT x1, x2, x1 * x2 FROM fixed); > ​Genius! It never occured to me that the with_query parameter could be used that

Re: [GENERAL] referencing other INSERT VALUES columns inside the insert

2015-11-16 Thread Albe Laurenz
Geoff Winkless wrote: > I know that this is something that can't be done... > > CREATE TABLE test (c1 int default 0, c2 int default 0, c3 int default 0); > INSERT INTO test (c1, c2, c3) VALUES (3, 7, c1 * c2); > > Is there a known trick to work around it (so that the values inserted into c1 > an

[GENERAL] referencing other INSERT VALUES columns inside the insert

2015-11-16 Thread Geoff Winkless
I know that this is something that can't be done... CREATE TABLE test (c1 int default 0, c2 int default 0, c3 int default 0); INSERT INTO test (c1, c2, c3) VALUES (3, 7, c1 * c2); Is there a known trick to work around it (so that the values inserted into c1 and c2 is referenced back to c3), other