Title
#general
f

fritz

08/25/2020, 1:12 PM
@ET I am assuming you are posting only a part of your query, you can't start a SQL query with
EXISTS
, 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.
1:15 PM
If you simply want the size of that file the query would be:
SELECT size from file WHERE path = '/tmp/et.txt'
The query will only return rows if a file exists at that path.
e

ET

08/25/2020, 1:26 PM
Thanks @fritz I want to get a boolean response to the question if the file exists or not
1:27 PM
I see you answer in the second thread
f

fritz

08/25/2020, 1:27 PM
@ET 👍
1:27 PM
Let me know if there is more help I can provide and I would be happy to assist.
e

ET

08/25/2020, 1:27 PM
10x! 🙂
f

fritz

08/25/2020, 1:31 PM
In general, I tend not to use
EXISTS
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
...