Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all, I'm trying to get a date from a database select, save it in a global variable and reuse the same variable to put it in a where clause. All inputs are postgresql database.
This is the select in object:
SELECT
"Postgres". "Public." "Importconfig." "Tables",
"Postgres". "Public." "Importconfig." "Datavalue"
FROM "postgres". "Public". "Importconfig"
where "postgres". "public". "importconfig". "datavalue"> '"+ (Date) globalMap.get (" MaxDate ")) +"'
and under the scheme I use.
This is the error:
Exception in component tDBInput_2 (test)
org.postgresql.util.PSQLException: ERROR: input syntax not valid for date type: "" + (Date) globalMap.get ("MaxDate")) + ""
Position: 203
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2440)
at org.postgresql.core.v3.QueryExecutorImpl.processResults (QueryExecutorImpl.java:2183)
at org.postgresql.core.v3.QueryExecutorImpl.execute (QueryExecutorImpl.java308)
at org.postgresql.jdbc.PgStatement.executeInternal (PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute (PgStatement.java:365)
at org.postgresql.jdbc.PgStatement.executeWithFlags (PgStatement.java307)
at org.postgresql.jdbc.PgStatement.executeCachedSql (PgStatement.java:293)
at org.postgresql.jdbc.PgStatement.executeWithFlags (PgStatement.java:270)
at org.postgresql.jdbc.PgStatement.executeQuery (PgStatement.java:224)
at local_project.test_0_1.test.tDBInput_2Process (test.java:1813)
at local_project.test_0_1.test.tDBInput_1Process (test.java:1201)
at local_project.test_0_1.test.runJobInTOS (test.java:2326)
at local_project.test_0_1.test.main (test.java:2171)
thank's
Hi,
You should use the PostgreSQL to_date function to convert the input string value instead of doing a java date conversion. The SQL query is first validated for correct syntax at java level and then at SQL level. Since you are adding a date directly to another string, its giving data type error.
eg:-
SELECT to_date('20170103','YYYYMMDD');
In you case, the most easy way is to assign the maxdate to a context variable in string data type where value is in YYYYMMDD format.
"SELECT Tables, Datavalue FROM postgres.Public.Importconfig where datavalue> to_date('"+context.max_date+"','YYYYMMDD')"
Warm Regards,
Nikhil Thampi
Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Hi,
You should use the PostgreSQL to_date function to convert the input string value instead of doing a java date conversion. The SQL query is first validated for correct syntax at java level and then at SQL level. Since you are adding a date directly to another string, its giving data type error.
eg:-
SELECT to_date('20170103','YYYYMMDD');
In you case, the most easy way is to assign the maxdate to a context variable in string data type where value is in YYYYMMDD format.
"SELECT Tables, Datavalue FROM postgres.Public.Importconfig where datavalue> to_date('"+context.max_date+"','YYYYMMDD')"
Warm Regards,
Nikhil Thampi
Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂