Subject Re: [firebird-support] [Fwd: "Illegal" subquery in if-clause]
Author Urs Liska
Thank you Helen and Svein,

IF (EXISTS(SELECT ausgabe_id
FROM sp_gedicht_ausgabenid (NEW.gedicht_id)
WHERE ausgabe_id = NEW.ausgabe_id))

solved the case.
I didn't even need the colon ;-)
I'll try to figure out what is going on there to learn something from
the problem...

Urs

>
> PSQL requires you to prefix variables with a colon when they are used
> in SQL statements. The subquery is SQL, even though the surrounding
> test is PSQL.
>
> You could try:
>
> IF (EXISTS( SELECT 1 FROM sp_gedicht_ausgabenid(:NEW.gedicht_id)
> WHERE ausgabe_id = :NEW.ausgabe_id)) THEN BEGIN ................
>
> If that won't work, then declare local variables for the two NEW
> context variables and use them instead.
>
> ./hb

> Hi Urs!
>
> Try
>
> IF EXISTS(SELECT * FROM sp_gedicht_ausgabenid(NEW.gedicht_id) sga
> WHERE sga.ausgabe_id = NEW.ausgabe_id)
>
> Note: I haven't tried it and don't know whether it works or not.
>
> HTH,
> Set