Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Life is difficult because it is non-linear.


devel / comp.databases.ingres / Re: MERGE syntax

SubjectAuthor
* MERGE syntaxRoy Hann
`- Re: MERGE syntaxRoy Hann

1
MERGE syntax

<uhdoq5$1k0nd$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=291&group=comp.databases.ingres#291

  copy link   Newsgroups: comp.databases.ingres
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: specia...@processed.almost.meat (Roy Hann)
Newsgroups: comp.databases.ingres
Subject: MERGE syntax
Date: Thu, 26 Oct 2023 13:15:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <uhdoq5$1k0nd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 26 Oct 2023 13:15:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ad08077fed4979a3d5d19c34b434a8bf";
logging-data="1704685"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GVTXbiwaaofknCFGa0aIQ8VE3uLU4g7g="
User-Agent: XPN/1.2.6 (Street Spirit ; Windows)
Cancel-Lock: sha1:YTQB0WIp62ilgGWhyFy6mMK8yxY=
 by: Roy Hann - Thu, 26 Oct 2023 13:15 UTC

I've recently run into a problem that cannot be solved except using a
MERGE statement. I should probably have taken an interest in it long ago
but...let's just say none of my customers like to be pioneers. Don't
dwell on that; just be pleased I'm finally using it.

The EBNF specification of the syntax in the SQL Guide is not quite right
(it doesn't indicate the keyword "THEN" has to precede the matching
action specification). But it does show that multiple matching actions
(UPDATE or DELETE) can be specified:

WHEN MATCHED [AND condition]
{UPDATE SET col = expr,... | DELETE}

I have not been able to quickly contrive an example with multiple UPDATE
actions that will even parse. For instance, ignoring the lack of any
mention of THEN, the above seems to allow:

MERGE INTO master_table t USING trx x
ON t.acct_no = x.acct_no
WHEN MATCHED AND x.acct_no = 2 OR x.acct_no = 99
THEN UPDATE SET balance = t.balance + x.balance
UPDATE SET balance = t.balance + -1.0
WHEN NOT MATCHED
THEN INSERT VALUES (x.acct_no, x.balance+10.)

but it elicits:

E_US09E6 line 1, Syntax error on 'UPDATE'. The correct syntax is:
MERGE INTO target-table [AS corr] USING table-ref ON join-condition
WHEN MATCHED [AND condition]
{UPDATE SET col = expr,... | DELETE}
WHEN NOT MATCHED [AND condition]
INSERT [(col-list)] VALUES (expr-list)

I've tried variations, like putting THEN before the second UPDATE as
well, but none work.

I am just trying to understand the syntax. I can't think of a reason to
ever do multiple updates with the same matching condition.

Roy

Re: MERGE syntax

<uhe4kp$1netn$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=292&group=comp.databases.ingres#292

  copy link   Newsgroups: comp.databases.ingres
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: specia...@processed.almost.meat (Roy Hann)
Newsgroups: comp.databases.ingres
Subject: Re: MERGE syntax
Date: Thu, 26 Oct 2023 16:37:45 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <uhe4kp$1netn$1@dont-email.me>
References: <uhdoq5$1k0nd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 26 Oct 2023 16:37:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ad08077fed4979a3d5d19c34b434a8bf";
logging-data="1817527"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mEPgEE/dibzEBqehPjAhORdthYR/llLk="
User-Agent: XPN/1.2.6 (Street Spirit ; Windows)
Cancel-Lock: sha1:PjALJ/G2isXRSeeKZtWglL8md2I=
 by: Roy Hann - Thu, 26 Oct 2023 16:37 UTC

Roy Hann wrote:

> I am just trying to understand the syntax. I can't think of a reason to
> ever do multiple updates with the same matching condition.

Unless someone tells me different, I'm starting to think this is just
another example where EBNF runs out of steam.

I think that description is just trying to tell us it doesn't matter
in what order we specify the DELETE action and the UPDATE action.
Semantically, we're allowed only one of each.

Am I right?

Roy

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor