Multivalue parameter in PostgreSQL function - jasper-reports

I am having a PostgreSQL function:
func(timestamp,timestamp,Integer[],varchar[])
I want to design a JasperReports report to fetch data from the function. For this, I created parameter of type list to take input from user and pass it as varchar array.
For this, I am trying to use the following query:
select * from func($P{interval_start}::timestamp,$P{interval_end}::timestamp,array[$P!{idParameter}],array[$P!{usersParameter}])
But when I am running the report, it gives error like column user1(passed from parameter) does not exist.
I also tried:
select * from func($P{interval_start}::timestamp,$P{interval_end}::timestamp,array[$P!{idParameter}],array[$P{usersParameter}])
But it says:
 Compiling to file... /home/Prashant/Desktop/jasper-report/report2.jasper
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid : 
1. Parameter type not supported in query : usersParameter class java.util.Collection
at net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:258)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:140)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:212)
at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:128)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:516)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Compilation running time: 73!
Please suggest, how to pass string array to PostgreSQL function from iReport?

Related

Spliting data in a db2 table using function

I'm trying to select data using below sql and created the following function to split the data but I get SQL0440n error.
The error "SQL0440n" simply means that a function (aka routine) in your SQL statement has not been found.
SQL0440N No authorized routine named "<routine-name>" of type
"<routine-type>" having compatible arguments was found.
If it is a user defined function, you will need to qualify it with a schema name when you use it, or alter your CURRENT PATH to let Db2 find the function by looking in a given set of schemas.
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0001014.html
If you still get the same error, check that the data-types of the input values to the function match, or are implicitly castable to the data-types in your function parameters

Why no output from Talend tMSSqlSP or tMSSqlRow

I am not new to ETL and trying to become familiar with Talend. I cannot seem to get any output of a stored procedure (using tMSSqlSP) or a query (using tMSSqlRow). NOTE: Things I read indicated that tMSSqlRow doesn't produce columnar output but not sure that is correct.
The job shown below runs but no output comes from the tMSSqlSP component. The trace debug shows that the output title is null. However, manual execution of the SP in SSMS succeeds, showing both objid and title.
The SP performs a simple query accepting a single input parameter (int) and outputs two columns -- the objid (int) and the title (string):
create procedure st_sp_case_title_get
#objid int
as
select [objid], [title] from [dbo].[table_case] where [objid] = #objid
You need to use tParseRecordSet in order to retrieve and parse result sets from tMSSqlRow and tMSSqlSP :
Define a column to be your result set (mine is called result) of type Object, in addition to your input columns (my input param is personid). In tMSSqlSP parameters tab, set personid as type IN, and result to be of type RECORD SET.
tParseRecordSet schema :
It parses the result column and gets Firstname and Lastname columns (your objid, and title columns)
tMSSqlRow is very similar. Check my previous answer here for an example.

Insert yyyyMMdd string into date column using Talend

I have the follow situation:
A PostgreSQL database with a table that contains a date type column called date.
A string from a delimited .txt file outputting: 20170101.
I want to insert the string into the date type column.
So far i have tried the following with mixed results/errors:
row1.YYYYMMDD
Detail Message: Type mismatch: cannot convert from String to Date
Explanation: This one is fairly obvious.
TalendDate.parseDate("yyyyMMdd",row1.YYYYMMDD)
Batch entry 0 INSERT INTO "data" ("location_id","date","avg_winddirection","avg_windspeed","avg_temperature","min_temperature","max_temperature","total_hours_sun","avg_precipitation") VALUES (209,2017-01-01 00:00:00.000000 +01:00:00,207,7.7,NULL,NULL,NULL,NULL,NULL) was aborted. Call getNextException to see the cause.
can see the string parsed into "2017-01-01 00:00:00.000000 +01:00:00".
When I try to execute the query directly i get a "SQL Error: 42601: ERROR: Syntax error at "00" position 194"
Other observations/attempts:
The funny thing is if I use '20170101' as a string in the query it works, see below.
INSERT INTO "data" ("location_id","date","avg_winddirection","avg_windspeed","avg_temperature","min_temperature","max_temperature","total_hours_sun","avg_precipitation") VALUES (209,'20170101',207,7.7,NULL,NULL,NULL,NULL,NULL)
I've also tried to change the schema of the database date column to string. It produces the following:
Batch entry 0 INSERT INTO "data" ("location_id","date","avg_winddirection","avg_windspeed","avg_temperature","min_temperature","max_temperature","total_hours_sun","avg_precipitation") VALUES (209,20170101,207,7.7,NULL,NULL,NULL,NULL,NULL) was aborted. Call getNextException to see the cause.
This query also doesn't work directly because the date isn't between single quotes.
What am i missing or not doing?
(I've started learning to use Talend 2-3 days ago)
EDIT//
Screenshots of my Job and tMap
http://imgur.com/a/kSFd0
EDIT//It doesnt appear to be a date formatting problem but a Talend to PostgreSQL connection problem
EDIT//
FIXED: It was a stupid easy problem/solution ofcourse. THe database name and schema name fields were empty... so it basically didnt know where to connect
You don't have to do anything to insert a string like 20170101 into a date column. PostgreSQL will handle it for you it's just ISO 8601's date format.
CREATE TABLE foo ( x date );
INSERT INTO foo (x) VALUES ( '20170101' );
This is just a talend problem, if anything.
[..] (209,2017-01-01 00:00:00.000000 +01:00:00,207,7.7,NULL,NULL,NULL,NULL,NULL)[..]
If Talend doesn't know by itself that passing timestamp into query requires it to be single quoted, then if possible - you need to do it.
FIXED: It was a stupid easy problem/solution ofcourse. THe database name and schema name fields were empty... so it basically didnt know where to connect thats why i got the BATCH 0 error and when i went deeper while debugging i found it couldnt find the table, stating the relation didnt exist.
Try like this,
The data in input file is: 20170101(in String format)
then set the tMap like,
The output is as follows:

SELECT query in PostgreSQL

I am trying to retrieve values from a PostgreSQL database in a variable using a WHERE clause, but I am getting an error.
The query is:
select age into x from employee where name=name.GetValue()
name is the textcontrol in which I am entering a value from wxpython GUI.
I am getting an error as name schema doesn't exist.
What is the correct method for retrieving values?
"name.GetValue()" is a literal string, you are sending that to your db which knows nothing about wxpython and nothing about the variables in your program. You need to send the value of that data to your db, probably using bound parameters. Something like:
cur.execute("select age from employee where name=%s", [name.GetValue()])
x = cur.fetchone()[0] # returns a row containing [age] from the db
is probably what you're after. This will create a query with a placeholder in the database, then bind the value of name.GetValue() to that placeholder and execute the query. The next line fetches the first row of the result of the query and assigns x to the first item in that row.
I'm not positive what you are trying to do, but I think your issue might be syntax (misuse of INTO instead of AS):
SELECT age AS x FROM employee WHERE name = ....

The default expression for the query parameter contains an error

I have a dataset referencing a proc. That proc takes in a #UserName
In my parameters of my dataset, I have specified a new param called #UserName and for its default value the expression =User!UserID but I still get this error when the report tires to render:
The default value expression for the query parameter #UserName contains an error [BC30654] 'Return' statement in a function, Get, or Operator must return a value
The only thing I can think of is that instead of modifying the existing datasource I had defined in the report, I removed and added a new datasource. I hope that doesn't matter as long as there is a valid data source for the report to go on that has those fields...I just switched this report to reference a copy of our current database for testing purposes.
Sounds like the report parameter is not being passed to the stored procedure.
In the Dataset Properties, click on the Parameters tab and check that the stored proc parameter #Username is correctly mapped to the Report parameter #Username.