pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

Support USING clause

Open Amrgt opened this issue 4 years ago • 4 comments

Hi,

By using the ALTER TABLE, I found out there is an issue regarding the ALTER COLUMN. E.g.,

Unexpected kw_using token: "using". Instead, I was expecting to see one of the following:

    - A "dot" token
    - A "lparen" token
    - A "kw_array" token
    - A "lbracket" token
    - A "semicolon" token

Would it be possible to add the USING clause? It would be useful for data migration when updating columns in a table.

For example:

CREATE TABLE example (
    id serial PRIMARY KEY,
    name TEXT NOT NULL,
    price VARCHAR 
);

INSERT INTO example(name,price) VALUES('ex','10');

Then we need the USING clause to migrate the existing data:

ALTER TABLE example ALTER COLUMN price TYPE INT USING price::integer

Amrgt avatar Mar 22 '21 12:03 Amrgt

Hi !

I dont have much time these days, but I'm adding that to my todo list.

Thanks for the report :)

oguimbal avatar Mar 23 '21 08:03 oguimbal

The using keyword is also unrecognized in delete statements, e.g.

delete from pending_password_reset p
using user_account u
where p.user_account_id = u.id
and u.email_address = '[email protected]';

The workaround would be something like this:

delete from pending_password_reset
where user_account_id in (
    select id
    from user_account
    where email_address = '[email protected]'
);

I dont have much time these days, but I'm adding that to my todo list.

I know the feeling! You've done amazing work so far.

steve-taylor avatar Oct 18 '21 11:10 steve-taylor

Looking forward to this feature :D

hiroshisiqueira avatar Apr 28 '23 21:04 hiroshisiqueira