Skip to main content

I need to write datetime to a comment on a SQL table after my postgres SQL writer is complete.

This can easily be done like when using a featureWriter like so:


COMMENT ON SCHEMA "my schema" IS '@DateTimeFormat(@DateTimeNow(), %Y-%m-%d %H:%M)';

This is not possible if i use a regular postgres writer. Only SQL functions are available. This alone is not enough to set a timestamp.
Tiny but frustrating neuance between almost identical transformer/writers. What other ways can i inject a datetime into my comment on schema syntax?

 

 

@ctredinnick will be able to help with this :)


Why not use instead:

COMMENT ON SCHEMA "my schema" IS LOCALTIMESTAMP(0); 
Or if really want the current datetime truncated to current minute
COMMENT ON SCHEMA "my schema" IS DATE_TRUNC(‘minute’,LOCALTIMESTAMP()); 

 


Why not use instead:

COMMENT ON SCHEMA "my schema" IS LOCALTIMESTAMP(0); 
Or if really want the current datetime truncated to current minute
COMMENT ON SCHEMA "my schema" IS DATE_TRUNC(‘minute’,LOCALTIMESTAMP()); 

 

I tried both examples (and other similar examples)
postgres throw an error using anything other than pure strings when setting commets. Thats why i need to use FME functions to inject the string directly into the SQL.

 syntax error at or near "DATE_TRUNC"

 


Hmmm, been years since had a PostGreSQL instance to design on.

Alright well this is a hack to create a dynamic string literal using FORMAT() and give a value formatted to a string literal with the %L format flag.

 

FME_SQL_DELIMITER ;

DO $$
BEGIN
EXECUTE FORMAT('COMMENT ON SCHEMA “my schema” IS %L', TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH:MM'));
END $$ LANGUAGE PLPGSQL;

 

 


Hmmm, been years since had a PostGreSQL instance to design on.

Alright well this is a hack to create a dynamic string literal using FORMAT() and give a value formatted to a string literal with the %L format flag.

 

FME_SQL_DELIMITER ;

DO $$
BEGIN
EXECUTE FORMAT('COMMENT ON SCHEMA “my schema” IS %L', TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH:MM'));
END $$ LANGUAGE PLPGSQL;

 

 

Thanks that worked! Thank you for the help :)


Reply