dbeaver icon indicating copy to clipboard operation
dbeaver copied to clipboard

Generate IN Statement

Open adzule opened this issue 9 years ago • 12 comments

A very useful feature I've seen in other apps is the ability to select (possibly non-contiguous) data in a column and then generate an IN () statement for it IE: IN (CELL1,CELL2,CELL3,CELL4). While this is mostly possible in DBeaver by using the Advanced Copy and replacing the newline character with a comma and then pasting into an IN () shell this is cumbersome and time consuming. A feature to allow Copy > As IN() Statement would be very useful and time saving. A similar feature is now available with the Order/Filter menu item however that applies the Column IN () filter to the current result set however it cannot be easily applied to different queries without waiting for the filter to complete, copying it from the filter box, and then pasting it into the query editor

Thanks for your time and efforts on a great product!

adzule avatar Nov 06 '17 22:11 adzule

It is similar to existing Generate SQL->SELECT .. WHERE .. IN feature. The only difference is that existing one uses only unique (primary) key columns for WHERE.

serge-rider avatar Nov 15 '17 05:11 serge-rider

I didn't know that was an option there. I cannot ever get that to work. It only ever says something about cannot detect source tables.

adzule avatar Nov 21 '17 02:11 adzule

Well, this works only if underlying table has some unique key. And you can't use it with joins or for views.

serge-rider avatar Jan 28 '18 21:01 serge-rider

@serge-rider , I would like to add my comments about the "Generate SQL" This is kind of feature request or at least a improve suggestion for this useful feature.

  1. Add it to support over custom queries, after all, is there where we work mostly; It is useless on the table->propertie->data most of the time.
  2. The WHERE and WHERE..IN option, we expected to generate the filter over the CELLs selected. Just like work in the SquirrelSQL .
  3. Remove the restriction of the WHERE..IN option for unique keys, there is no make sense in most of the situations.

ceinmart avatar Apr 10 '19 17:04 ceinmart

This makes sense but it is not really clear how it should work. What column should be in WHERE clause? I guess we can use currently selected column. But if multipel columns are selected?

Say, we have following custom SQL query:

select f.title, f.fulltext
from public.film f
inner join public.inventory i on f.film_id = i.film_id
where i.store_id=1
order by f.title

What exactly SELECT .. WHERE .. IN query must be generated in this case?

serge-rider avatar Apr 13 '19 13:04 serge-rider

Where ___ in ... And ___ in... Based on present and selected field headers, even if different than table field names (select x as y, use y).

I would expect, as in other similar applications, that the IN statements would be generated with IN statements relevant to the data in the selected columns only.

If I do a query like "Select x.a, y.b 'purple' as c from x join y' and highlight say two rows in the last two columns of the result and choose to generate the where in it should generate: "WHERE b in (###,###) and c in ('purple','purple','purple')"

(Edited to correct Auto Correct and add more details.

On Sat, Apr 13, 2019, 8:08 AM Serge Rider [email protected] wrote:

This makes sense but it is not really clear how it should work. What column should be in WHERE clause? I guess we can use currently selected column. But if multipel columns are selected?

Say, we have following custom SQL query:

select f.title, f.fulltextfrom public.film finner join public.inventory i on f.film_id = i.film_idwhere i.store_id=1order by f.title

What exactly SELECT .. WHERE .. IN query must be generated in this case?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dbeaver/dbeaver/issues/2484#issuecomment-482807749, or mute the thread https://github.com/notifications/unsubscribe-auth/AK8FQJDzPUKKh06xmxPJLKYcsIHcOrgpks5vgdbXgaJpZM4QT9lo .

adzule avatar Apr 13 '19 20:04 adzule

This makes sense but it is not really clear how it should work. What column should be in WHERE clause? I guess we can use currently selected column. But if multipel columns are selected?

Say, we have following custom SQL query:

select f.title, f.fulltext
from public.film f
inner join public.inventory i on f.film_id = i.film_id
where i.store_id=1
order by f.title

What exactly SELECT .. WHERE .. IN query must be generated in this case?

Ok, for me the SQL generated should be only the "colname IN ( value1, value2, ...) AND colname2 IN (value1,value2,...) ". Only column name, without table/alias . All this only for the cells selected in the grid .

The other part of the SQL the user should write it. The focus in this resource is to make easier to create filters based on data already returned. If the user is working with custom SQL, the SQL already is written.

ceinmart avatar Apr 15 '19 15:04 ceinmart

already implemented for column filters in the resultset

uslss avatar Jun 08 '21 10:06 uslss

Hi @uslss ,

Please, can you enlight me on how to use this resource on column filters??? I'm trying and trying here on version 21.1 and found no way to generate the "IN" statement with the data from the cells selected.

ceinmart avatar Jun 08 '21 12:06 ceinmart

hi @ceinmart , you could choose needed cells and then press filter icon at column title, so needed values will be automatically selected or you can just press filter icon at the column title and choose needed values and than apply filters. At the top table toolbar you can find automatically generated IN statement (see gif attached). Filters could be apply for one and more columns. Does it resolve your issue? 2021-06-08_15h45_42

uslss avatar Jun 08 '21 12:06 uslss

Nice! I never thought of use this resource this way. Thanks!

ceinmart avatar Jun 08 '21 13:06 ceinmart

I am using Mysql and when I select several rows from the data grid and click on Generate SQL I do not get the option SELECT .. WHERE .. IN. I only see SELECT .. WHERE .. =. It would be very useful to be able to get the SQL using an IN clause

PaulDokken avatar Sep 29 '21 15:09 PaulDokken