Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] DML Table-Join Support: USING clause in delete and FROM clause in update #738

Closed
nocaway opened this issue Jan 10, 2019 · 4 comments
Assignees
Labels
kind/enhancement This is an enhancement of an existing feature
Milestone

Comments

@nocaway
Copy link
Contributor

nocaway commented Jan 10, 2019

USING in delete and FROM in update are for listing the tables that are to be accessed by WHERE clause. These clauses should be supported to allow join in the DML statements.

Examples:
DELETE FROM a_table USING another_table WHERE a_table.id = another_table.id;
UPDATE a_table SET col = xxx FROM another_table WHERE a_table.id = another_table.id;

@nocaway nocaway added the kind/enhancement This is an enhancement of an existing feature label Jan 10, 2019
@ajcaldera1
Copy link
Contributor

I see that UPDATE FROM is documented for 1.2, but when I attempt to use it, I get a cryptic message:

alan=# CREATE TABLE product_segment (                                                                                                      ID SERIAL PRIMARY KEY,                                                                                                                 
segment VARCHAR NOT NULL,                                                                                                              discount NUMERIC (4, 2));

alan=# INSERT INTO product_segment (segment, discount)                                                                                 VALUES                                                                                                                                   
  ('Grand Luxury', 0.05),
  ('Luxury', 0.06),  
  ('Mass', 0.1);

CREATE TABLE product(  
 id serial primary key,
                                                                                                                 name varchar not null,                                                                                                                 price numeric(10,2),                                                                                                                   net_price numeric(10,2),                                                                                                               segment_id int not null);

alan=# INSERT INTO product (name, price, segment_id)                                                                                   VALUES ('diam', 804.89, 1),                                                                                                                ('vestibulum aliquet', 228.55, 3),                                                                                                     ('lacinia erat', 366.45, 2),                                                                                                           ('scelerisque quam turpis', 145.33, 3),                                                                                                ('justo lacinia', 551.77, 2),                                                                                                          ('ultrices mattis odio', 261.58, 3),                                                                                                   ('hendrerit', 519.62, 2),                                                                                                              ('in hac habitasse', 843.31, 1),                                                                                                       ('orci eget orci', 254.18, 3),                                                                                                         ('pellentesque', 427.78, 2),                                                                                                           ('sit amet nunc', 936.29, 1),                                                                                                          ('sed vestibulum', 910.34, 1),                                                                                                         ('turpis eget', 208.33, 3),                                                                                                            ('cursus vestibulum', 985.45, 1),                                                                                                      ('orci nullam', 841.26, 1),                                                                                                            ('est quam pharetra', 896.38, 1),                                                                                                      ('posuere', 575.74, 2),                                                                                                                ('ligula', 530.64, 2),                                                                                                                 ('convallis', 892.43, 1),                                                                                                              ('nulla elit ac', 161.71, 3);

alan=# UPDATE product                                                                                                                  SET net_price = price - price * discount                                                                                             
  FROM                                                                                       
                                            product_segment                                                                                                                        WHERE                                                                                                                                  product.segment_id = product_segment.id;
ERROR:  System column with id -1 is not supported yet

@nocaway
Copy link
Contributor Author

nocaway commented Mar 20, 2019

Thanks @ajcaldera1 , it's a documentation error. I'll update the doc.
And yes, we need to fix error messages also.

@ndeodhar ndeodhar added this to the v2.0 milestone Jul 17, 2019
@xvaara
Copy link

xvaara commented Apr 21, 2020

Is there any progress on this?

@ndeodhar ndeodhar modified the milestones: v2.0, v2.2.x Jun 5, 2020
@nocaway nocaway assigned m-iancu and ndeodhar and unassigned nocaway Jun 8, 2020
@ndeodhar ndeodhar assigned ndeodhar and m-iancu and unassigned m-iancu and ndeodhar Jul 6, 2020
jaki pushed a commit that referenced this issue Aug 3, 2020
… (#5262)

This pull request enables USING clause in DELETE and FROM clause in UPDATE in gram.y for queries like:

DELETE FROM a_table USING another_table WHERE a_table.id = another_table.id;
UPDATE a_table SET col = xxx FROM another_table WHERE a_table.id = another_table.id;

Tests for such queries are present in TestPgUpdate.java and TestPgDelete.java.

This effectively closes Issue #738.

This pull request was originally part of the larger pull request #5190 (now edited) which has now been broken down into 4 separate pull requests: #5190 (edited), #5262, #5263, #5264.
@jaki
Copy link
Contributor

jaki commented Aug 3, 2020

Close by commit 09d0f9c.

@jaki jaki closed this as completed Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement This is an enhancement of an existing feature
Projects
None yet
Development

No branches or pull requests

7 participants