@schuemie,
I’m adding some requested features to CohortExpression builder, and one of the requests to CREATE TABLE on the target table if it does not exist. I added this block of code to my script, but it doesn’t execute on postgres properly:
IF OBJECT_ID('cohort', 'U') IS NULL
create table cohort
(
cohort_definition_id int,
subject_id bigint,
cohort_start_date datetime,
cohort_end_date datetime
);
Doesn’t work. I overheard a comment that the sql render looks for a pattern of dropping the target table and then creating it, but for my purposes, i will never ever ever (ever ever ever ever ever) drop a table on the user’s behalf. But, i’m willing to try to create the table if it doesn’t exist.
Hence, do we need a new pattern recognizer in sqlrender to detect if a table exists that is cross platform? For the specific postgres I found this query:
SELECT EXISTS (
SELECT 1
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'schema_name'
AND c.relname = 'table_name'
);
Can sqlrender handle this transformation?
-Chris