SELECT Object IF EXISTS Object ELSE INSERT
See original GitHub issueHi, I tried to use the IF…ELSE and EXISTS clauses in order to construct a query that either selects an item if it exists or else inserts it. So since I can do the following:
SELECT 1 IF EXISTS (SELECT Person FILTER .name = 'Ryan Gosling')
....... ELSE (SELECT 0);
…I tried to do
SELECT Person FILTER .name = 'Ryan Gosling'
....... IF EXISTS (SELECT Person FILTER .name = 'Ryan Gosling')
....... ELSE (SELECT <int64>{});
However I get the error: QueryError: operator ‘std::IF’ cannot be applied to operands of type ‘std::bool’, ‘std::bool’, ‘std::int64’
Am I making some syntax error or is this kind of selection not allowed? I assumed it would work because the documentation on IF states anytype
as the left assignment, but I have not been able to figure out how to make it work with my schema types.
Thank you very much for your help.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (12 by maintainers)
Top Results From Across the Web
how to update an object in array if exists , other wise add it as ...
You can use Array.find() to find any matching items. You'd then update if an existing item has been found, or add a new...
Read more >Overview of the T-SQL If Exists statement in a SQL Server ...
Overview of the T-SQL If Exists statement in a SQL Server database ; EXISTS. (. SELECT *. FROM sys.objects. WHERE object_id = OBJECT_ID(N'dbo....
Read more >on trigger upsert: if value not found in select , create a new row ...
Save this question. Show activity on this post. I am having a beastly time trying to in a trigger, check the oldmap vs...
Read more >SQL Server stored procedure if exists update else insert
In this tutorial, we will learn about SQL Server stored procedure if exists update else insert. And we will also implement some examples....
Read more >9.6: JSON Functions and Operators - PostgreSQL
Function Return Type Example Result
json_array_length(json). jsonb_array_length(jsonb) int 5
json_each_text(json). jsonb_each_text(jsonb) setof key text, value text key | value...
json_object_keys(json). jsonb_object_keys(jsonb) setof text json_object_k...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To be clear
SELECT Foo ?? Bar
already works as a concise spelling ofSELECT Foo IF EXISTS Foo ELSE Bar
, it’s just thatINSERT
specifically doesn’t respect the flow and is always executed.I’ve created a gist, if anyone needs… https://gist.github.com/Mulugruntz/97d904db4446428d0815dd626b812cbd