db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-6723) Allow derived table as a source in MERGE statement
Date Mon, 01 Sep 2014 09:03:20 GMT

    [ https://issues.apache.org/jira/browse/DERBY-6723?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14117220#comment-14117220

Knut Anders Hatlen commented on DERBY-6723:

I believe the standard does allow it, but it is currently disabled because of some technical
challenges when the source table is not a base table. There is a similar request for allowing
views as source (DERBY-6656), and it sounds as if the underlying problem that needs to be
solved, is the same for both of these issues.

> Allow derived table as a source in MERGE statement
> --------------------------------------------------
>                 Key: DERBY-6723
>                 URL: https://issues.apache.org/jira/browse/DERBY-6723
>             Project: Derby
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions:
>            Reporter: Aleksei Kovura
>            Priority: Minor
> I'm trying to utilize MERGE to do an upsert operation like this:
> MERGE INTO "APP"."ST_KEY_VAL" trg USING (SELECT * FROM (VALUES ('key1', 'val1')) as t1
(st_key, st_val)) as src
> ON trg.st_key = src.st_key
> WHEN MATCHED THEN UPDATE SET st_val = src.st_val
> WHEN NOT MATCHED THEN INSERT VALUES (src.st_key, src.st_val)
> ;
> Derby returns an error:
> Error: The source table of a MERGE statement must be a base table or table function.
> SQLState:  42XAL
> ErrorCode: 30000
> MERGE is used this way on other databases, unfortunately I can't find whether it is standard
compliant or not. If this gets implemented, I would use it in PreparedStatement, replacing
values with "?"-s.

This message was sent by Atlassian JIRA

View raw message