I am new to CrateDB, new to postgresql, and so so with sql in general.
I am trying to execute the following sql statements but keep getting an error and cannot figure out what is going on:
IF EXISTS(SELECT 1 FROM crate.doc.schema_versions WHERE script_name = ‘DbUpDemo.Scripts.Script0001-InitialCreate.sql’) THEN
select 'if was true';
else
select ‘if was NOT true’;
end if;
I keep getting this error:
SQL Error [XX000]: ERROR: line 1:7: mismatched input ‘IF’ expecting {‘SELECT’, ‘DEALLOCATE’, ‘FETCH’, ‘END’, ‘WITH’, ‘CREATE’, ‘ALTER’, ‘KILL’, ‘CLOSE’, ‘BEGIN’, ‘START’, ‘COMMIT’, ‘ANALYZE’, ‘DISCARD’, ‘EXPLAIN’, ‘SHOW’, ‘OPTIMIZE’, ‘REFRESH’, ‘RESTORE’, ‘DROP’, ‘INSERT’, ‘VALUES’, ‘DELETE’, ‘UPDATE’, ‘SET’, ‘RESET’, ‘COPY’, ‘GRANT’, ‘DENY’, ‘REVOKE’, ‘DECLARE’}
Where: io.crate.exceptions.SQLExceptions.esToCrateException(SQLExceptions.java:211)…
However the following query returns 1 record with a ‘t’:
select EXISTS(SELECT 1 FROM crate.doc.schema_versions WHERE script_name = ‘DbUpDemo.Scripts.Script0001-InitialCreate.sql’)