我有一个table1(id - unique)
public class TimeoutInterceptor implements HttpRequestInterceptor {
private int requestTimeout = 1 * DateTimeConstants.MILLIS_PER_MINUTE;
private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
public TimeoutInterceptor() { }
public TimeoutInterceptor(final int requestTimeout) {
this.requestTimeout = requestTimeout;
}
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
if (request instanceof AbstractExecutionAwareRequest) {
final AbstractExecutionAwareRequest abortableRequest = (AbstractExecutionAwareRequest) request;
setAbort(abortableRequest);
} else if (request instanceof HttpRequestWrapper) {
HttpRequestWrapper wrapper = (HttpRequestWrapper) request;
this.process(wrapper.getOriginal(), context);
}
}
/**
* @param abortableRequest
*/
private void setAbort(final AbstractExecutionAwareRequest abortableRequest) {
final SoftReference<AbstractExecutionAwareRequest> requestRef = new SoftReference<AbstractExecutionAwareRequest>(abortableRequest);
executorService.schedule(new Runnable() {
@Override
public void run() {
AbstractExecutionAwareRequest actual = requestRef.get();
if (actual != null && !actual.isAborted()) {
actual.abort();
}
}
}, requestTimeout, TimeUnit.MILLISECONDS);
}
public void setRequestTimeout(final int requestTimeout) {
this.requestTimeout = requestTimeout;
}
}
和table2
|---|----------|
|id | array |
|---|----------|
|0 | [2, 4, 6]|
|1 | [3, 5, 1]|
|---|----------|
我现在不知道如何提出这样的请求:
|---|----|
|id |val |
|---|----|
|1 | 23 |
|2 | 34 |
|3 | 19 |
|4 | 61 |
|5 | 47 |
|6 | 3 |
|---|----|
或者更简单,这不起作用:
SELECT val FROM table2 WHERE id = ANY(SELECT array FROM table1 WHERE id = 1)
虽然这有效:
select 2 = any (select array[2, 4]);
ERROR: operator does not exist: integer = integer[]
LINE 1: select 2 = any (select array[2, 4]);
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
答案 0 :(得分:1)
1)
Regex r = new Regex("src=\"(?<src>[^\"]+)\"")
2)
SELECT val FROM table2
WHERE id = ANY((SELECT array FROM table1 WHERE id = 1)::int[])
3)
SELECT val FROM table2
WHERE ARRAY[id] <@ (SELECT array FROM table1 WHERE id = 1)
4)
SELECT val FROM table2
WHERE id in (SELECT unnest(array) FROM table1 WHERE id = 1)
5)正如你所看到的,有很多可能性;)