WITH unexpected error for multi-line queries in SQLDelight-PostgreSQL

56 Views Asked by At

I am trying to run an insert query where it will check if the record exist and make an entry only if there is no record. And since it is an multi-line query i have to enclose the entire query in curly braces. Here is my query:

insert
{
WITH
  extant AS (
    SELECT id FROM my_table WHERE (phone) = ('108123403115')
  )
  inserted AS (
    INSERT INTO my_table (phone)
    SELECT '108123403115'
    WHERE NOT EXISTS (SELECT FROM extant)
    RETURNING id;
  )
SELECT id FROM inserted
UNION ALL
SELECT id FROM extant
}

And the error that am getting is:

'{' expected, got 'WITH'
2    WITH
     ^^^^

I have setup the multi-line query under the tag insert and tried taking off the curly braces as well. But nothing seems to work.

0

There are 0 best solutions below