ERROR: invalid input syntax for type numeric: "N/A" ... nice but which column? - postgresql

I am running a function in PostgreSQL which contains several functions which purpose is to load data from foreign tables into mine. While running I get this error:
[SELECT - 0 row(s), 762.353 secs] [Error Code: 0, SQL State: 22P02] ERROR: invalid input syntax for type numeric: "N/A"
Where: PL/pgSQL function import_data_3(integer,timestamp with time zone,timestamp with time zone,integer) line 16 at SQL statement
SQL statement "SELECT import_data_3(import, beg, end_t, is_l)"
PL/pgSQL function data_import_all(timestamp with time zone,timestamp with time zone,integer,integer) line 31 at PERFORM
I know what that means and also its reason I am trying to convert 'N/A' string to number and there for this error, problem is this lousy error does not specify the column where the error occurred.
Is there a way to get more precise error message which would tell me the exact column where the error happened?

It's not in the column but in one of the parameters that are passed to import_data_3.
You called the query SELECT import_data_3(import, beg, end_t, is_l).
The specification of this function is import_data_3(integer,timestamp with time zone,timestamp with time zone,integer)
Since you got the error
invalid input syntax for type numeric: "N/A"
this most likely means that either first parameter "import" or the last one "is_l" contain the value "N/A". Try to debug the calling code of the function data_import_all and see how those two parameter values are generated.

Related

ERROR: syntax error at or near "%" when creating a table column variable

I am trying to create a composite type which contains a variable of table column type as below
create type gp_core.rec_key_transaction as(
CODE_TRANSACTION transaction_.CODE_TRANSACTION%TYPE
);
I get the below error
ERROR: syntax error at or near "%"
LINE 2: ... TYPE_TRANSACTION TRANSACTION_.TYPE_TRANSACTION%TYPE
SQL state: 42601
Character: 99
I have no idea what could be the problem...
The reason for the error is, that the syntax simply isn't supported.
If you want to create type where one attribute is a record of a "table type", there is no need for the %type to begin with. For every table (and view) a type with the same name is created. So if transaction_.code_transaction is an existing table, you can create your type as:
create type gp_core.rec_key_transaction as
(
CODE_TRANSACTION transaction_.CODE_TRANSACTION
);
But I honestly fail to see the usefulness of this approach. Why not just use the "table type" directly instead of wrapping it with another type?

How to determine PostgreSQL Error Codes from error message

In a PL/pgSQL function, I want to trap an error. For example, when I convert text to a number, I get an error (I run it in psql, but get the same error in the Postico GUI client):
select 'a'::numeric;
ERROR: invalid input syntax for type numeric: "a"
LINE 1: select 'a'::numeric;
^
To trap this error, I made an EXCEPTION-clause like this:
CREATE OR REPLACE FUNCTION public.to_number(input text) RETURNS numeric
AS $$
BEGIN
RETURN input::numeric;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END
$$
LANGUAGE plpgsql
IMMUTABLE
RETURNS NULL ON NULL INPUT
;
However, I don't like the condition WHEN OTHERS.
How do I map the error message ERROR: invalid input syntax for type numeric: "a" to one mentioned in the Appendix A. PostgreSQL Error Codes?
I want to catch the conversion error when converting to numeric and no other conditions (as the above function is a simplified one).
I have the feeling I'm missing something, but what?
When you get the error in psql, run
\errverbose
and you'll get information like
ERROR: 22P02: invalid input syntax for type numeric: "a"
LINE 1: select 'a'::numeric;
^
LOCATION: set_var_from_str, numeric.c:6856
22P02 is the SQLSTATE, and Appendix A of the documentation will tell you that that is invalid_text_representation.

FB3.0 Dateadd() throws syntax error in where section of query

I am trying to compare the date modified (field type: Timestamp) with a value that is based off of a month before the current date. I keep getting a syntax error when using the function DateAdd().
I Am Using Libreoffice base 6.2.3.2 (x64) and firebird 3.0 embedded
Using this code, I get a result returning no records but no error
Select *
From "tblPart"
Where "Date Modified" = Current_Timestamp
but anytime I want to use the Dateadd() function, I get an error
Select *
From "tblPart"
Where
"Date Modified"< Dateadd(Month,-1,Current_Timestamp)
Expected to Return a list of results that have been modified over a month ago.
Errors:
SQL Status: HY000
Error code: 1000
Syntax error in SQL statement
SQL Status: HY000
Error code: 1000
SQL Status: HY000
Error code: 1000
syntax error, unexpected $end, expecting BETWEEN or IN or SQL_TOKEN_LIKE
//EDIT: Added the programs that I used
I ran into the same problem. Though the SQL-statement with DateAdd() has been suggested as working, LO Base answered the query with a message box
Syntax error in SQL statement
Why it should work
In contrast the same SQL statement like in the query succeeded by running it in the "Execute SQL Statement" window (LO Base' main window menu "tools" > "SQL…").
Solution
What finally got my query to work was to check "Run SQL command directly" in the toolbar or in the "Edit" menu.
This prevents LO from analyzing the SQL query before execution. This fails, because it is not understanding the full SQL statement (firebird's DateAdd()-function), and thus is the reason for the mentioned errors.

Why am I getting a syntax error when calling my stored procedure?

I am trying to call a stored procedure with Time variable as in parameter. But whenever i try to call the procedure i m getting error as:
db2 'call PASS_FAIL_CHECKDATE('2014-01-21','13:42:25','CSS1',Null,'4500096651','10',Null)'
SQL0104N An unexpected token ":42" was found following "CKDATE(2014-01-21,
13". Expected tokens may include: "+". SQLSTATE=42601
My Procedures input parameter are :
PASS_fail_checkdate (in post_date date,in post_time time,in destplant varchar(4), in destloc varchar(4), in transnum varchar(10), in translineitemnum varchar(6), in inboundconsignment varchar(35))
I am not sure if my declaration for time variable is correct in procedure or if i am calling the time variable correctly in the procedure.
Please give me suggestions on the same.
As already offered, in words, try the following example as a revision to what was noted in the OP as tried already but failing; i.e. change to use double-quote vs the apostrophe, specified as the delimiter for the DB2 SQL statement string:
db2 "call PASS_FAIL_CHECKDATE('2014-01-21','13:42:25','CSS1',Null,'4500096651','10',Null)"

Getting an error when using a date parameter

I am using iReport 5.0.1. I created a date parameter and am using it in my query:
When I preview the report, I enter my date parameter:
After I enter all the parameters and run the report, I get this error:
Error filling print... Error executing SQL statement for : Sample
net.sf.jasperreports.engine.JRException: Error executing SQL statement for : Sample
at com.jaspersoft.jrx.query.PlSqlQueryExecuter.createDatasource(PlSqlQueryExecuter.java:143)
at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1086)
at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:667)
at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1258)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:877)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:822)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "Feb"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at com.jaspersoft.jrx.query.PlSqlQueryExecuter.createDatasource(PlSqlQueryExecuter.java:136)
... 12 more
Print not filled. Try to use an EmptyDataSource...
What is going on here, and how do I fix this? Thanks!
I think the ! in $P!{...} means to include the parameter's literal value in the report.
Try using $P{start_date} and $P{end_date}, both without the !.
Effectively, your SQL statement is using:
and finalinsdate >= Feb/18/2013
That is not a valid SQL statement, which means PostgreSQL will complain with:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "Feb"
For next time, copy and paste the source code, instead of taking a screen capture.