Question

invalid input syntax for type numeric

Asked by: tankergoblin

say i have below:
CREATE TABLE test.testing
(
  studentid character varying(5),
  amount_paid numeric
)

and i try to insert

INSERT INTO test.testing(
            studentid, amount_paid)
    VALUES ('beb123', '' );

and i received this message

ERROR:  invalid input syntax for type numeric: ""

********** Error **********

ERROR: invalid input syntax for type numeric: ""
SQL state: 22P02

is that mean null is not allowed in numeric data type

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-05-12 at 23:27:33ID24403794
Tags

postgresql

Topic

PostgreSQL Database

Participating Experts
3
Points
500
Comments
11

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. validate numeric
    Hello, can someone write me a simple field validate javascript to validate that the data entered to the field is numeric? My form name is : deluxe the field to validate is : quantity thanks alot!
  2. Roman numeral to decimal
    Hi: can anyone give me a hint about how to convert a number entered in Roman numerals to decimal? The program should consist of a class, say Roman. a) Store the number as a ROman numberal. b) Convert and store the number into decimal. c) Print the number as a ROman numbera...
  3. Casting a null as numeric
    Here is my statement: insert into FairIsaac.dbo.Bankrupcy SELECT Col014, Col015, Col016, Col017, Col018, Col019, Col020, Col021, Col022, Col023, Col024, Col025, Col026, Col027, Col028, Col029, Col030, Col031, Col032, Col033, Col034, CAST(Col035 as numeric(2,0)), CAST(C...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: phuctranPosted on 2009-05-12 at 23:35:45ID: 24371922

why do you want to have null in numeric field?  It will make your life more difficult later.
http://www.databasedesign-resource.com/null-values-in-a-database.html


 

by: geowrianPosted on 2009-05-12 at 23:51:36ID: 24371983

You are putting an empty string into a numeric field. You need to put a number there or NULL (no quotes)

 

by: tankergoblinPosted on 2009-05-12 at 23:55:54ID: 24371995

how to put NULL

like this?
INSERT INTO ediprice_a.testing(
            studentid, amount_paid)
    VALUES ('beb123',  );
i receive error too

 

by: tankergoblinPosted on 2009-05-12 at 23:56:56ID: 24371998

why do you want to have null in numeric field?  It will make your life more difficult later.

what you suggest me to do.
my data is in number and null will happen in that column..

 

by: geowrianPosted on 2009-05-12 at 23:59:07ID: 24372004

Like this:
INSERT INTO ediprice_a.testing(
            studentid, amount_paid)
    VALUES ('beb123',  NULL);

 

by: geowrianPosted on 2009-05-13 at 00:01:35ID: 24372017

@phuctran
Agreed in general, but it's not always possible or  most effective. I would suggest that the OP consider putting 0 instead of NULL as that is the most logical value to be placed in that field. Putting NULL in that field will make your coding and SQL later more complicated as it will have to check for NULL values before doing calculations on that field.

 

by: phuctranPosted on 2009-05-13 at 16:27:44ID: 24380596

I cannot say what number should you put in that field but you should not put null there even though the field allows you to do so.  For example, if that field is always positive (high, length, hours ...) then you can put a negative number instead of null.  Depends on your situation.  As geowrian said, 0 is a good one.

 

by: tankergoblinPosted on 2009-05-13 at 18:33:42ID: 24381142

but if i want to left it blank is it possible

also i insert data into database is base on the data in a text file. that mean i m manually add data into database.

example:
in my text file i have

name  mark
alex   54
helen
david 44

how to put 0 in mark on helen row.

i dun understand why postgresql numeric data type cannot accept empty column...

 

by: tankergoblinPosted on 2009-05-13 at 18:34:33ID: 24381145

if there is no other way and by putting 0 is only solution then how can i put 0 on each empty column detected

 

by: cminearPosted on 2009-05-14 at 07:31:38ID: 24385403

geowrian did give an example of how to perform an INSERT with a NULL; or as has been pointed out in your other question, you can just drop that column from the list of column names and don't submit the "" value to it.
  INSERT INTO ediprice_a.testing(studentid) VALUES ('beb123');

As to the issue of NULL vs. 0, as you show in your example data file, there isn't a value for the mark, so don't force it.  Yes, there are many good arguments for why NULLs should be avoided in a database.  But there are also many uses for them.  And arguments about NULLs making the SQL coding harder are just an excuse for not wanting to think about or cope with what they may mean to the underlying model.

As an example, let's say we want a table for recording patient visits to a doctor's office.  It could have a schema like this (just trying to capture enough for my example --- not intended to be complete).
Visit:  patient_id, visit_id, height, weight, arrival, departure, notes

Every time a patient visits, they are expected to have their height and weight measured.  But there may be cases where weight isn't measured: the scale is currently broken, a new assistant forgets to do it, or the patient has a stroke on the way to the scale.   (It's not likely, but it could happen.)  Do we enter "0" for the weight, or leave it empty (NULL)?  I would say we leave it empty, because that easily conveys that "we do not know what the weight is."  If we put in 0 just so we don't have a NULL, we are opening ourselves to a different coding issue which may be hidden and thus easily get missed.

Say we have a report generated to get the minimum, maximum and average weights of patients.  With the 0's in there, it gives us a skewed average and a wrong minimum.  "So just check that the weight is not zero" could be the answer.  My counter-answer is "and how is this any different than checking that the value is not NULL?"

The point is you have to think critically about your model.  If a value should never be empty, not even temporarily, then you make the column NOT NULL and you go on.  But if there are valid reasons with your data where a value could be unknown, then you let the NULLs be added to the database and deal with them, because that is just how your data lays out.  Yes, "amount_paid' does tend to suggest that it should always have a value.  But if you just put in "0" when you don't know the value, how do you then tell when something was given away for free (also "0")?  If you instead enter "-1" for NULL, how do you then tell when you paid to have some person take the item, rather than that person paying you (opposite transaction means negative)?

 

by: phuctranPosted on 2009-05-14 at 10:01:36ID: 24386971

It is true that you can use null in your numeric field and it is based on your situation to use or not use null.  The results are the same.  

However, to me, a numeric field should not have null values.  When I query a numeric field, I expect a number.  If the height of a patient is 0, I know that it is not true right away.  Normally, I query then save into variables in my program.  I just don't want to get a null value where I expect a number.  Of course, "just write a query that change null to 0" before return the recordset.  That is true also.  There are many ways to get to the destination.  To me, it is easier that the numeric field has numbers.

So, maybe in your situation, it is easier to have null in the numeric field.

@cminear
For the "amount_paid" you pointed out, to me, I have to raise the error message (log, email, ...) for that record and do not place a null or 0 in the field (negative does not work).  I would not place anything in the database that I am not sure.  If the field is the number of incoming calls and you don't have it in your importing text file, then it may be safe to use 0 (in some extreme cases, it is not).  So, basically, using null or numbers depends on your data.  To me, I will try not use null if possible.  In that way, I can force that when anyone writes a INSERT query to save into database, he/she must know what fields he/she is saving because the numeric field is NOT NULL.

Anyway, this is just my opinion.  I am sorry that I did not give any solutions for the OP.


20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...