fritz
08/25/2020, 1:12 PMEXISTS
, you presumably want to have some form of a SELECT
statement. Furthermore, your EXISTS
pattern does not make sense as written.
If I wrote:
SELECT 'test' AS foo WHERE EXISTS(SELECT size from file WHERE path = '/tmp/et.txt');
The logic executed would be the following.
Select a given string ('test' AS foo
), if a path matching: '/tmp/et.txt'
exists in the file
table.
Because size
is not constrained in the WHERE
clause it has no bearing on the output of the query. Likewise it will never be _SELECT_ed because you are using an EXISTS
condition which operates like a boolean. If you wanted to sub-select size
for your '/tmp/et.txt' file you would need to modify your query.
Using EXISTS here is duplicative and the same goal could be accomplished without it by doing the following:
SELECT 'test' AS foo WHERE (SELECT 1 FROM file WHERE path = '/tmp/et.txt');
---
I assume you are trying to do something else here but it is hard to guess based on the snippet alone. If you tell me the exact use-case you are trying to solve for, I would be more than happy to help you craft the SQL.SELECT size from file WHERE path = '/tmp/et.txt'
The query will only return rows if a file exists at that path.ET
08/25/2020, 1:26 PMfritz
08/25/2020, 1:27 PMET
08/25/2020, 1:27 PMfritz
08/25/2020, 1:31 PMEXISTS
as it's rarely needed instead of a simple WHERE(SUB QUERY)
NOT EXISTS
on the other hand is often useful to me. For example, let's say I wanted to get all the system_info
for a device that wasn't running the 'foobarbaz' process:
SELECT * FROM system_info WHERE NOT EXISTS (SELECT 1 FROM processes WHERE name = 'foobarbaz');
---
hostname = fritz-imac.lan
uuid = E664D52B-5FBC-....
cpu_type = x86_64h
cpu_subtype = Intel x86-64h Haswell
cpu_brand = Intel(R) Xeon(R) W-2140B CPU @ 3.20GHz
cpu_physical_cores = 8
cpu_logical_cores = 16
cpu_microcode =
physical_memory = 34359738368
hardware_vendor = Apple Inc.
hardware_model = iMacPro1,1
hardware_version = 1.0
...