pgadmin-org / pgadmin-org/pgadmin4
Generate INSERT or UPDATE or DELETE commands from results
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 891
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 8
Description
I would like to suggest a new feature that can be added to the copy options.
In the current version, you can copy the result set with or without the headers,
the new feature will enable you to copy the data in a format of INSERT or UPDATE or DELETE.
for example:
- table structure: my_table (id int primary key, name text, updatedate timestamp, age int)
- query "select * from my_table"
- the result will be:
id (integer) | name (text) | updatedate (timestamp) | age (int)
1 | john | 2024-09-07 00:00:01.000| 18
2 | tra | 2024-09-07 00:00:01.000| 36
3 | volta | 2024-09-07 00:00:01.000| 72
there will be 1 more option in the "Copy options": 'Custom'.
when choosing custom, a dialog will be opened.
in that dialog you can select which dml action you want, and some configurations for each DML option.
the DML options:
-
Copy as INSERT
will copy like so:
INSERT INTO public.my_table (id, name, updatedate, age) VALUES (1, 'john', '2024-09-07 00:00:01.000', 18);
INSERT INTO public.my_table (id, name, updatedate, age) VALUES (2, 'tra', '2024-09-07 00:00:01.000', 36);
INSERT INTO public.my_table (id, name, updatedate, age) VALUES (3, 'volta', '2024-09-07 00:00:01.000', 72); -
Copy as UPDATE
will copy like so:
UPDATE public.my_table SET name = 'john', updatedate = '2024-09-07 00:00:01.000', age = 18 WHERE id = 1;
UPDATE public.my_table SET name = 'tra', updatedate = '2024-09-07 00:00:01.000', age = 36 WHERE id = 2;
UPDATE public.my_table SET name = 'volta', updatedate = '2024-09-07 00:00:01.000', age = 72 WHERE id = 3; -
Copy as DELETE
will copy like so:
DELETE FROM public.my_table WHERE id = 1;
DELETE FROM public.my_table WHERE id = 2;
DELETE FROM public.my_table WHERE id = 3;
it should work based on the table structure, so for example UPDATE and DELETE condition will be based on Primary Key.
the actual values can be treated based on the column data type which already presented in the result set, so text, dates and so on will be encapsulated in quotes ('like so'), integer wont be encapsulated,
special data types will just be used in cast like so: 'data'::custom_dt.
Drawbacks:
- Complex query with more than one table.
- No primary key or any unique column in result set or in table
- Incremental id or generated uuid pk column
- TBD...
Solutions:
- Open dialog where a table name can be set
- Open dialog where a column can be set as the "primary key" in the condition
it can result bad queries (for example if I only query name and age and I set WHERE condition to be 'name' and there are duplicates, UPDATE commands will update multiple records, but its by design and its the responsibility of the person that works on DB. - checkbox for including pk in INSERT commands.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue does not name files or tests; start by locating the result-set Copy options UI and the table-metadata handling it relies on. Review how copy formats and PostgreSQL column types are represented, then define the dialog and DML behavior described in the issue, including primary-key conditions and the listed drawbacks. Done means the requested INSERT, UPDATE, and DELETE output works for supported table results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100