Select from Java Strings

Поиск
Список
Период
Сортировка
Искать

Select from Java Strings

От:
Daron Ryan <daron.ryan@gmail.com>
Дата:
I have strings from
        java and need to check which ones are not present in the db. Can
        I use a select statement to do this by making it search my
        strings as though they are a table?

Re: Select from Java Strings

От:
David Johnston <polobo@yahoo.com>
Дата:


On Jul 3, 2011, at 11:13, Daron Ryan <daron.ryan@gmail.com> wrote:

I have strings from java and need to check which ones are not present in the db. Can I use a select statement to do this by making it search my strings as though they are a table?

There are multiple ways to accomplish your goal, which each have merits and issues.  
1. Java for loop and look for each string one at a time
2. Convert your strings into a Postgres array and query all of them at once
3. Insert your strings into a table and execute a query to check them all at once

If you want more help than this you should provide more specific details about your situation.  Your question seems odd at first reading, especially the part where you want to find out which strings are NOT present.

David J

Re: Select from Java Strings

От:
Daron Ryan <daron.ryan@gmail.com>
Дата:
Hello David,
    
    This is a simplified version of my own attempt:
    
    SELECT *
    FROM ("oxford", "webster")
    WHERE NOT ( columnName = ANY (SELECT name FROM dictionaries))
    
    The idea is that "oxford" and "webster" come from the Java program
    end up in the column called columnName.
    
    I think your answer is quite sufficient though and that it I should
    use option 1 since there don't seem to be any other options which
    are any better.
    
    Thanks,
    Daron.
    
    
    On 4/07/2011 1:45 AM, David Johnston wrote:
    
On Jul 3, 2011, at 11:13, Daron Ryan <daron.ryan@gmail.com> wrote: I have strings from java and need to check which ones are not present in the db. Can I use a select statement to do this by making it search my strings as though they are a table? There are multiple ways to accomplish your goal, which each have merits and issues.   1. Java for loop and look for each string one at a time 2. Convert your strings into a Postgres array and query all of them at once 3. Insert your strings into a table and execute a query to check them all at once If you want more help than this you should provide more specific details about your situation.  Your question seems odd at first reading, especially the part where you want to find out which strings are NOT present. David J

Re: Select from Java Strings

От:
Harald Fuchs <hari.fuchs@gmail.com>
Дата:
In article <4E116E11.1030209@gmail.com>,
Daron Ryan  writes:

> Hello David,
> This is a simplified version of my own attempt:

> SELECT *
> FROM ("oxford", "webster")
> WHERE NOT ( columnName = ANY (SELECT name FROM dictionaries))

> The idea is that "oxford" and "webster" come from the Java program end up
> in the column called columnName.

If the list is not very long, you could use a VALUES expression:

SELECT g.x
FROM (VALUES ('oxford'), ('webster')) AS g(x)
WHERE g.x NOT IN (SELECT name FROM dictionaries)
FAQ