472,804 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

<no subject>

Hi @ all,

I think thats a bug:

SELECT '#' || '#'

will work but

SELECT '#' || CAST(NULL AS VARCHAR)

will return only empty rows.
My Query looks like this : SELECT field1 || field2 FROM ...
If field2 ISNULL then everything is null. CAST does not help.

thanks for your help

Daniel
__________________________________________________ ____________________________
Die Besten ihrer Klasse! WEB.DE FreeMail (1,7) und WEB.DE Club (1,9) -
bei der Stiftung Warentest - ein Doppelsieg! http://f.web.de/?mc=021184
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #1
9 1759
On Wednesday 01 October 2003 10:57, Daniel Schuchardt wrote:
Hi @ all,

I think thats a bug:

SELECT '#' || '#'

will work but

SELECT '#' || CAST(NULL AS VARCHAR)
Nope - not a bug.
will return only empty rows.
My Query looks like this : SELECT field1 || field2 FROM ...
If field2 ISNULL then everything is null. CAST does not help.


Broadly speaking VALUE op NULL = NULL
You'll see similar issues with comparisons. You might find the article below
useful:

http://techdocs.postgresql.org/guides/BriefGuideToNulls
--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #2
But CAST(NULL AS VARCHAR) should make it a varchar so i should be able
to || the both values. So perhaps a bug in CAST.

The only way here would be to make a CASE WHEN - i think thats not a
good behavoir.

Daniel

On Wednesday 01 October 2003 10:57, Daniel Schuchardt wrote:
Hi @ all,

I think thats a bug:

SELECT '#' || '#'

will work but

SELECT '#' || CAST(NULL AS VARCHAR)
Nope - not a bug.
will return only empty rows.
My Query looks like this : SELECT field1 || field2 FROM ... If field2
ISNULL then everything is null. CAST does not help.


Broadly speaking VALUE op NULL = NULL
You'll see similar issues with comparisons. You might find the article
below
useful:

http://techdocs.postgresql.org/guides/BriefGuideToNulls

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

Nov 12 '05 #3
> But CAST(NULL AS VARCHAR) should make it a varchar so i should be able
to || the both values. So perhaps a bug in CAST.

The only way here would be to make a CASE WHEN - i think thats not a
good behavoir.


NULL is null even it have varchar type, it is not an empty string. Try to do
the following:

select field1 || case when field2 is null then '' else field2 end from
my_big_table;

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #4
Read the docs...

Hm looking towards the doks thats the right behavoir. Also from the
logical point thats the right behavoir. But I don't like it. The CAST
should return an empty string in that case (looking from the practical
standpoint).

Hm.
-----Ursprüngliche Nachricht-----
Von: de*@archonet.com [mailto:de*@archonet.com]
Gesendet: Mittwoch, 1. Oktober 2003 12:08
An: Daniel Schuchardt; pg***********@postgresql.org
Betreff: Re: [GENERAL] <no subject>
On Wednesday 01 October 2003 10:57, Daniel Schuchardt wrote:
Hi @ all,

I think thats a bug:

SELECT '#' || '#'

will work but

SELECT '#' || CAST(NULL AS VARCHAR)
Nope - not a bug.
will return only empty rows.
My Query looks like this : SELECT field1 || field2 FROM ... If field2
ISNULL then everything is null. CAST does not help.


Broadly speaking VALUE op NULL = NULL
You'll see similar issues with comparisons. You might find the article
below
useful:

http://techdocs.postgresql.org/guides/BriefGuideToNulls
--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #5
On Wed, 2003-10-01 at 04:57, Daniel Schuchardt wrote:
Hi @ all,

I think thats a bug:

SELECT '#' || '#'

will work but

SELECT '#' || CAST(NULL AS VARCHAR)

will return only empty rows.
My Query looks like this : SELECT field1 || field2 FROM ...
If field2 ISNULL then everything is null. CAST does not help.


You want to use COALESCE.

--
-----------------------------------------------------------------
Ron Johnson, Jr. ro***********@cox.net
Jefferson, LA USA

"Our computers and their computers are the same color. The
conversion should be no problem!"
Unknown
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #6
On Wed, 2003-10-01 at 11:19, Daniel Schuchardt wrote:
But CAST(NULL AS VARCHAR) should make it a varchar


NULL is still null, whatever you cast it to. The column type is
independent of whether one particular datum is null.

Instead of casting, you want COALESCE(field2, '') to give you an empty
string if the value is null.

--
Oliver Elphick Ol************@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Yet if any man suffer as a Christian, let him not be
ashamed; but let him glorify God on this behalf."
I Peter 4:16
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #7
On Wednesday 01 October 2003 11:32, Daniel Schuchardt wrote:
Read the docs...

Hm looking towards the doks thats the right behavoir. Also from the
logical point thats the right behavoir. But I don't like it. The CAST
should return an empty string in that case (looking from the practical
standpoint).


Many would (probably will) disagree.

AFAIK in SQL NULLs are typed, so it's perfectly reasonable to have a null
int4, null varchar etc.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #8
On Wed, 2003-10-01 at 11:32, Daniel Schuchardt wrote:
Read the docs...

Hm looking towards the doks thats the right behavoir. Also from the
logical point thats the right behavoir. But I don't like it. The CAST
should return an empty string in that case (looking from the practical
standpoint).


All CAST is doing is changing the type of the datum; it does not change
its value except perhaps as a side effect. A null string is not the
same as an empty string. I don't at all see why you should expect
anything different, especially when the COALESCE() function is already
provided to do exactly what you want.

--
Oliver Elphick Ol************@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Yet if any man suffer as a Christian, let him not be
ashamed; but let him glorify God on this behalf."
I Peter 4:16
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #9
Oh thanks, thats it. I don't know that function.

Now I agree ;-)
Thanks
Daniel

-----Ursprüngliche Nachricht-----

All CAST is doing is changing the type of the datum; it does not change
its value except perhaps as a side effect. A null string is not the
same as an empty string. I don't at all see why you should expect
anything different, especially when the COALESCE() function is already
provided to do exactly what you want.

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

http://archives.postgresql.org

Nov 12 '05 #10

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

Similar topics

4
by: Skip Montanaro | last post by:
(moving over from webmaster mailbox) scott> I'm sorry for bothering you, but I've tried to post to the Python scott> Tutor Mail List, tried to get someone from Bay PIggies to scott> respond, but...
0
by: D. K. | last post by:
Hi; > I have installed suse 8.2 a short while ago and at my first attempt to connect mysql (via shell and a perl dbi script) i get following error: > > can't connect to mysql server through socjet...
4
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I...
18
by: Timothy Casey | last post by:
Thanks in advance... =~= Timothy Casey South Australia worloq@iprimus.com.au Formerly: casey@smart.net.au
1
by: Anders Both | last post by:
Why does my asp.net application sometimes write into the debug window The thread '<No Name>' (0x974) has exited with code 0 (0x0). ?
1
by: Bob | last post by:
The thread '<No Name>' (0x29c) has exited with code 0 (0x0) What is this and why do I see it occasionally in the Output screen? Bob
4
by: David Lozzi | last post by:
Howdy, I'm using a WYSIWYG editor called TinyMCE. When I edit some text and then save it back to my SQL server using a SQLCommand, all HTML characters are changed to HTML code, i.e. &gt;strong&lt;...
4
by: Charlie Brown | last post by:
The thread '<No Name>' (0xedc) has exited with code 0 (0x0) While debugging appplications, I often see this message popup in the VS output window. Although I havent specifically written any...
3
by: my cats, Gag and yak | last post by:
the following keeps showing up in Application_Error I have re-installed VS2008 and it still happens I do not know what this means, thank you your help. {Name = "EventArgs" FullName =...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.