Re: DELETE ... USING LATERAL

2021-10-07 Thread Nikhil Benesch
On Mon, Oct 4, 2021 at 3:21 PM Tom Lane wrote: > Not sure what to tell you about the state of the idea that the > target table could be re-specified in FROM/USING. I'm hesitant > to close the door on it permanently, because people do periodically > wish to be able to left-join the target to somet

Re: DELETE ... USING LATERAL

2021-10-04 Thread Tom Lane
Michael Lewis writes: > On Mon, Oct 4, 2021, 10:30 AM Nikhil Benesch > wrote: >> # delete from int_arrays using int_arrays; >> ERROR: table name "int_arrays" specified more than once >> Don't you need to use an alias for the table in the using clause? You could, but then you'd be creating a se

Re: DELETE ... USING LATERAL

2021-10-04 Thread Tom Lane
Nikhil Benesch writes: > On Mon, Oct 4, 2021 at 1:48 PM Tom Lane wrote: >> My mental model of these things is that the target table is cross-joined >> to the additional tables as though by a comma in FROM [...] > Mine as well. > I just managed to dredge up some history here though. Turns out yo

Re: DELETE ... USING LATERAL

2021-10-04 Thread Michael Lewis
On Mon, Oct 4, 2021, 10:30 AM Nikhil Benesch wrote: > you can't reuse the FROM table name in the USING clause: > > # delete from int_arrays using int_arrays; > ERROR: table name "int_arrays" specified more than once > Don't you need to use an alias for the table in the using clause?

Re: DELETE ... USING LATERAL

2021-10-04 Thread Nikhil Benesch
On Mon, Oct 4, 2021 at 1:48 PM Tom Lane wrote: > My mental model of these things is that the target table is cross-joined > to the additional tables as though by a comma in FROM [...] Mine as well. I just managed to dredge up some history here though. Turns out you explicitly disabled this featu

Re: DELETE ... USING LATERAL

2021-10-04 Thread Tom Lane
Nikhil Benesch writes: > Is it intentional that LATERAL elements in a USING clause of a DELETE > statement can't reference the table declared in the FROM clause? Hmm ... doesn't work for UPDATE, either. My mental model of these things is that the target table is cross-joined to the additional ta

DELETE ... USING LATERAL

2021-10-04 Thread Nikhil Benesch
Is it intentional that LATERAL elements in a USING clause of a DELETE statement can't reference the table declared in the FROM clause? Here's a somewhat contrived example. Suppose I have a table with one jsonb column: create table int_arrays (int_array jsonb); insert into int_arrays value

Re: Using Lateral

2018-03-28 Thread Johann Spies
Thanks David and Paul, You have helped me a lot. Regards Johann. On 28 March 2018 at 20:49, David G. Johnston wrote: > On Tuesday, March 27, 2018, Johann Spies wrote: >> >> In the past I could use this in a query: >> >> SELECT >> DISTINCT ut, >> CASE >> WHEN xpa

Using Lateral

2018-03-28 Thread David G. Johnston
On Tuesday, March 27, 2018, Johann Spies wrote: > In the past I could use this in a query: > > SELECT > DISTINCT ut, > CASE > WHEN xpath_exists ('//t:address_spec/t:country/text()', > q.address_spec, > p.ns) > THEN unnest

Re: Using Lateral

2018-03-28 Thread Paul Jungwirth
On 03/28/2018 05:22 AM, Johann Spies wrote: Thanks Paul. I was hesitant to post my full query. It is a long and complicated query. Ha ha, you aren't joking. :-) With something that long I don't think I'd want to split every xpath call into a new join. I guess you could try it and see though

Re: Using Lateral

2018-03-28 Thread Johann Spies
Thanks Paul. I was hesitant to post my full query. It is a long and complicated query. But here it is now: WITH p AS ( SELECT ARRAY [ ARRAY [ 't', 'http://scientific.thomsonreuters.com/schema/wok5.4/public/FullRecord' ] ] AS ns), uts AS ( SELECT s.ut FROM wos

Re: Using Lateral

2018-03-27 Thread Paul Jungwirth
On 03/27/2018 03:22 AM, Johann Spies wrote: In the past I could use this in a query: SELECT DISTINCT ut, CASE WHEN xpath_exists ('//t:address_spec/t:country/text()', q.address_spec, p.ns) THEN unnest (xpath ('//t:

Using Lateral

2018-03-27 Thread Johann Spies
In the past I could use this in a query: SELECT DISTINCT ut, CASE WHEN xpath_exists ('//t:address_spec/t:country/text()', q.address_spec, p.ns) THEN unnest (xpath ('//t:address_spec/t:country/text()', q