Skip site navigation (1) Skip section navigation (2)

data type of string literal

From: nobs(at)nobswolf(dot)info (Emil Obermayr)
To: pgsql-novice(at)postgresql(dot)org
Subject: data type of string literal
Date: 2008-02-26 08:42:05
Message-ID: 20080226084205.GH3103@nobswolf.info (view raw or flat)
Thread:
Lists: pgsql-novice
Hi List,

I just joined because I found a behaviour of implicit casts I don't
understand. I am quite new to Postgre, trying out things and 
tried this sql-code:

select cast('8.000' as text) = 8.00 as test, 1 as case
union 
select cast('8.000' as text) = 8.000, 2
union  
select '8.00' = 8.000, 3

This gives me the following result:

test => f	case => 1
test => t	case => 2
test => t	case => 3

Why is the string literal in case 3 parsed as float so the 
comparision is true. While in the other cases the 
float literal is auto-casted to a string, so the 
comparision is only true if the number of zeros is equal?

Is there a exact column type that fits a string literal? Explicit
casts to char or varchar instead of text gives the same results.

Yours,

Emil 'nobs' Obermayr

Responses

pgsql-novice by date

Next:From: Michael GlaesemannDate: 2008-02-26 13:11:01
Subject: Re: data type of string literal
Previous:From: Tom LaneDate: 2008-02-24 22:22:26
Subject: Re: Logging Question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group