473,408 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

string is sometimes null ?

Hiya
I have written a PL/PGSQL function which tots up users accounting
information from their RADACCT data on the fly. So each insert or
update modifies their totals.

This has worked without error when I have tested it by hand with hand
crafted inserts and updates, however when I put it on the actual live
accounting server (both systems are running 7.4.3) it seems to work
partially.

The RADIUS server is reporting problems when trying to write START of
accounting entries, and the error given is:

ERROR: cannot EXECUTE a null querystring CONTEXT: PL/pgSQL function
"radacct_trig" line 43 at open

The lines its refering to are:

--- START ---

str:=''SELECT
username,year_of_jan,current_in,current_out,curren t_start,last_update,m''||monthcurr||''_in AS monthin,m''||monthcurr||''_out AS monthout
FROM customer_stats WHERE username=''''''||username||'''''''';

OPEN curs FOR EXECUTE str;

--- END ---

str is defined as a varchar(255). What could be causing str to be NULL
when the execute is caused? I would have thought if some of the
variables were null that it would have complained about a malformed SQL
query but this is saying the string is NULL!

any ideas help much appreciated, thanks.

--
-----
Graeme Hinchliffe (BSc)
Core Internet Systems Designer
Zen Internet (http://www.zen.co.uk/)

Direct: 0845 058 9074
Main : 0845 058 9000
Fax : 0845 058 9005

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #1
5 3853

On Wed, 29 Sep 2004, Graeme Hinchliffe wrote:
The RADIUS server is reporting problems when trying to write START of
accounting entries, and the error given is:

ERROR: cannot EXECUTE a null querystring CONTEXT: PL/pgSQL function
"radacct_trig" line 43 at open

The lines its refering to are:

--- START ---

str:=''SELECT
username,year_of_jan,current_in,current_out,curren t_start,last_update,m''||monthcurr||''_in
AS monthin,m''||monthcurr||''_out AS monthout
FROM customer_stats WHERE username=''''''||username||'''''''';


If monthcurr or username are null, the above will be null.
Anything || NULL => NULL.
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #2
> If monthcurr or username are null, the above will be null.
Anything || NULL => NULL.


AH! thanks sorted it now. That is not the behaviour I would have
expected :)

Is there a concatination operator that will not do this? IE

if

var1 || var2 || var3

and var2 is null would result in just var1var3 ?

Many thanks for your help

--
-----
Graeme Hinchliffe (BSc)
Core Internet Systems Designer
Zen Internet (http://www.zen.co.uk/)

Direct: 0845 058 9074
Main : 0845 058 9000
Fax : 0845 058 9005

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #3
Graeme Hinchliffe wrote:
If monthcurr or username are null, the above will be null.
Anything || NULL => NULL.


AH! thanks sorted it now. That is not the behaviour I would have
expected :)

Is there a concatination operator that will not do this? IE
if
var1 || var2 || var3

and var2 is null would result in just var1var3 ?


You could use coalesce(var1,'') || coalesce(var2,'')
Or, wrap that in your own function and create your own operator.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,
Is there a concatination operator that will not do this? IE
var1 || var2 || var3
and var2 is null would result in just var1var3 ?


You have to coalesce your vars before concatenating, as in

coalesce(var1,'') || coalesce(var2,'') || coalesce(var3,'')

Mit freundlichem Gruß / With kind regards
Holger Klawitter
- --
lists <at> klawitter <dot> de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFBW9CJ1Xdt0HKSwgYRAjg9AJoCA8rZYcDxsdey1neJNj ysnPByagCfUIeL
CJT69fhzoIY+RG8btBrPnCA=
=YsB2
-----END PGP SIGNATURE-----

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #5
On Thu, 30 Sep 2004, Graeme Hinchliffe wrote:
If monthcurr or username are null, the above will be null.
Anything || NULL => NULL.


AH! thanks sorted it now. That is not the behaviour I would have
expected :)

Is there a concatination operator that will not do this? IE

if

var1 || var2 || var3

and var2 is null would result in just var1var3 ?


You can use coalesce as suggested... However, since you are building a
statement, think about what you want to do when either of those are NULL.
You might want to use an empty string, or perhaps instead of ='' you might
actually be wanting an IS NULL clause, etc...

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

Nov 23 '05 #6

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

Similar topics

14
by: Charles L | last post by:
I don't know if this is a stupid quesiton or not. I would like to know how to convert an array of characters generated from a previous operation to a string ie how do I append a null character at...
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
4
by: Locusta | last post by:
Hello, I have been struggeling for replacing a string in a string. The snippet from the program below replaces the <, & and > with the XML equivalent values. In the program, I allocate space...
8
by: ais523 | last post by:
I use this function that I wrote for inputting strings. It's meant to return a pointer to mallocated memory holding one input string, or 0 on error. (Personally, I prefer to use 0 to NULL when...
9
by: Jacob | last post by:
Is there any way (maybe using an attribute) that I can force strings or other reference parameters to always have an instance even if they are blank? Ex: public string DoSomething(string Text)...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
4
by: Lloyd Dupont | last post by:
to store user preference in our application we have an 'hand written' XML file. (as opposed to XmlSerializer written one, which crash sometimes, on some user's computer, for some unknown reason.....
4
by: Jay | last post by:
For a column that contains a string (let's say varchar), is there any performance advantage in not allowing nulls, and using an empty string ("") to instead?
1
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I generally work on web apps, but I am dealing with a Winform right now and may be missing something really basic. I have a combobox and I would like to know what value has been selected....
6
by: shapper | last post by:
Hello, I have a method: Roles(CultureInfo culture, RoleType? type, bool? open, bool? beginWithEmpty, string userRoles) How can I pass an empty string as userRoles? I tried:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.