473,772 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determining how to convert a value

Using pl/pgSQL on 7.4.3, I have a varchar column called unit name in a table that can be numeric, of course. Most of the time, end users will put A, B, C, D, etc. or 101, 102, 103, etc. I am trying to write a function to determine the next available number after the first is given. For instance, so far I have a function that will determine 102 is next if 101 was used firstby using the int2() function to convert it first. But, of course, I get anerror 'ERROR: invalid input syntax for integer: "A"' if they use A first because A is not numeric. How can I try the value with int2() first and thenpass it to the appropriate function instead of int2() like below or determine the type of value first?

CREATE OR REPLACE FUNCTION "public"."next_ unit_name" (integer) RETURNS varchar AS'
DECLARE
similargroup alias for $1;
unit record;
BEGIN
SELECT INTO unit public.tblhudun its.unit_name FROM public.tblhudun its WHERE (public.tblhudu nits.similar_gr oup_id = similargroup) ORDER BY public.tblhudun its.unit_name DESC;
IF FOUND AND unit.unit_name <> '''' THEN
return int2(unit.unit_ name) + 1;
ELSE
return ''101'';
END IF;

END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

--
Robert
Nov 23 '05 #1
1 1590
No equivalent to Isnumeric in pgsql that I am aware of. You could create another function to do this. See http://www.webservertalk.com/archive...-5-206410.html

Using Perl instead of pgsql might be easier.

Mike
On Sun, Jul 11, 2004 at 04:35:53PM -0400, Robert Fitzpatrick wrote:
Using pl/pgSQL on 7.4.3, I have a varchar column called unit name in a table that can be numeric, of course. Most of the time, end users will put A, B, C, D, etc. or 101, 102, 103, etc. I am trying to write a function to determine the next available number after the first is given. For instance, so far I have a function that will determine 102 is next if 101 was used first by using the int2() function to convert it first. But, of course, I get an error 'ERROR: invalid input syntax for integer: "A"' if they use A first because A is not numeric. How can I try the value with int2() first and then pass it to the appropriate function instead of int2() like below or determine the type of value first?

CREATE OR REPLACE FUNCTION "public"."next_ unit_name" (integer) RETURNS varchar AS'
DECLARE
similargroup alias for $1;
unit record;
BEGIN
SELECT INTO unit public.tblhudun its.unit_name FROM public.tblhudun its WHERE (public.tblhudu nits.similar_gr oup_id = similargroup) ORDER BY public.tblhudun its.unit_name DESC;
IF FOUND AND unit.unit_name <> '''' THEN
return int2(unit.unit_ name) + 1;
ELSE
return ''101'';
END IF;

END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

--
Robert


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5425
by: Luca | last post by:
I have the following problem: I'm developing a system where there are some processes that communicate each other via message queues; the message one process can send to another process is as follows: ****************************************** struct ST_MSG { int iType; char aData; }
7
1915
by: GregT | last post by:
I program in C#. Is there a way to determine which of the local machine's logical drives are associated with CD drive(s)?
2
3646
by: Garrett | last post by:
Need any help in determining which groups have been given security access to a folder. Searched DirectoryServices to no avail... Any Help?
7
11954
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return "DirectoryEntry" objects within the path that I specify (either using the DirectoryEnrtry.Children or using the DirectorySearcher class) and all started well and dandy! Now the problem; some of the properties of the DirectoryEntry objects being...
10
1516
by: Daniel R. Rossnagel | last post by:
As I can determining if string can be turned to a numerico value?, since to contain alfanumeric data it returns an error to me. as I can avoid the following error? String str="123"; int valInt = Convert.ToInt32(str); //OK String str="StringXX" int valInt = Convert.ToInt32(str); //ERROR
2
4556
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following:
3
2901
by: planetthoughtful | last post by:
Hi All, I'm trying to determine the number of days between today and the value in a datetime field in a table. It appears my version of MySQL doesn't have DATEDIFF available, so I'm wondering if there's another method to achieve the same result as: SELECT DATEDIFF(CURDATE(),`mydate`) AS numdays FROM tblArticles WHERE artid = 10
4
2119
by: Nathan Sokalski | last post by:
When determining whether a String can be converted to a DateTime, you can use the IsDate() method. However, I would also like to know whether the string is a date, a time, or both a date and a time. Is there any simple way to do this without using manual pattern matching? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
53
4965
by: Aaron Gray | last post by:
Due to M$'s stupidity in not making DOMElements first class citizens the following will not work :- function isElement( o) { return o instanceof Element } It works for FF, Opera and Safari.
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.