Select from Java Strings

Started by Daron Ryanalmost 15 years ago4 messagesgeneral
Jump to latest
#1Daron Ryan
daron.ryan@gmail.com

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
<span class="Apple-style-span" style="border-collapse: separate;
color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style:
normal; font-variant: normal; font-weight: normal; letter-spacing:
normal; line-height: normal; orphans: 2; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; font-size: medium;"><span
class="Apple-style-span" style="border-collapse: collapse;
font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 13px;
line-height: 17px; white-space: pre-wrap;">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?</span></span>
</body>
</html>

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Daron Ryan (#1)
Re: Select from Java Strings

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

#3Daron Ryan
daron.ryan@gmail.com
In reply to: David G. Johnston (#2)
Re: Select from Java Strings

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hello David,<br>
<br>
This is a simplified version of my own attempt:<br>
<br>
SELECT *<br>
FROM ("oxford", "webster")<br>
WHERE NOT ( columnName = ANY (SELECT name FROM dictionaries))<br>
<br>
The idea is that "oxford" and "webster" come from the Java program
end up in the column called columnName.<br>
<br>
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.<br>
<br>
Thanks,<br>
Daron.<br>
<br>
<br>
On 4/07/2011 1:45 AM, David Johnston wrote:
<blockquote
cite="mid:C6F72661-0FFC-4C25-876B-DEDB9408A016@yahoo.com"
type="cite">
<div><br>
<br>
On Jul 3, 2011, at 11:13, Daron Ryan &lt;<a
moz-do-not-send="true" href="mailto:daron.ryan@gmail.com">daron.ryan@gmail.com</a>&gt;
wrote:<br>
<br>
</div>
<blockquote type="cite">
<div> <span class="Apple-style-span" style="border-collapse:
separate; color: rgb(0, 0, 0); font-family: 'Times New
Roman'; font-style: normal; font-variant: normal;
font-weight: normal; letter-spacing: normal; line-height:
normal; orphans: 2; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
font-size: medium;"><span class="Apple-style-span"
style="border-collapse: collapse; font-family:
Tahoma,Arial,Helvetica,sans-serif; font-size: 13px;
line-height: 17px; white-space: pre-wrap;">I have strings
from<br>
java and need to check which ones are not present in the
db. Can<br>
I use a select statement to do this by making it search my<br>
strings as though they are a table?</span></span> </div>
</blockquote>
<br>
<div>There are multiple ways to accomplish your goal, which each
have merits and issues.  </div>
<div>1. Java for loop and look for each string one at a time</div>
<div>2. Convert your strings into a Postgres array and query all
of them at once</div>
<div>3. Insert your strings into a table and execute a query to
check them all at once</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>David J</div>
<div><br>
</div>
</blockquote>
<br>
</body>
</html>

#4Harald Fuchs
hari.fuchs@gmail.com
In reply to: Daron Ryan (#1)
Re: Select from Java Strings

In article <4E116E11.1030209@gmail.com>,
Daron Ryan <daron.ryan@gmail.com> 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)