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

Implicit cast of literal in SQL statements

From: Scott Royston <scroyston71(at)yahoo(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Implicit cast of literal in SQL statements
Date: 2001-12-27 20:37:14
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugspgsql-hackers
I've seen a few postings in multiple newsgroups saying that in 7.1.x and 
up, literals in SQL statements are implicitly cast to strings.

For example in:
select distinct 'hello' from mytable;
the 'hello' is implicitly assumed to be 'hello'::text

However, in both 7.1.3, and a fresh build of 7.2b4 from cvs, (with all 
regressions passing) I get:

mytest=# select distinct 'hello' from mytable;
ERROR:  Unable to identify an ordering operator '<' for type 'unknown'
         Use an explicit ordering operator or modify the query

an explicit 'hello'::text works fine.

I've spent a day looking through the code and can't really find any 
obvious #define's or compile time flags that would be causing this 
It looks like
Const *
make_const(Value *value)
                 case T_String:
                         val = DirectFunctionCall1(textin, 

                         typeid = UNKNOWNOID;    /* will be coerced 
later */
                         typelen = -1;           /* variable len */
                         typebyval = false;

does the damage, and it never gets 'coerced later', at least not before 
transformDistinctClause(...) gets called, which is where the failure 
happens (a few levels down).

does this really work for everybody else?  Can someone point me to a 
compile flag I may be missing, or the code that actually does the 
implicit cast?


Do You Yahoo!?
Get your free address at


pgsql-hackers by date

Next:From: Pavlo BaronDate: 2001-12-27 20:37:40
Subject: Re: patch: INSERT INTO t VALUES (a, b, ..., DEFAULT, ...)
Previous:From: Pavlo BaronDate: 2001-12-27 16:19:51
Subject: Re: patch: INSERT INTO t VALUES (a, b, ..., DEFAULT, ...)

pgsql-bugs by date

Next:From: Tom LaneDate: 2001-12-27 21:22:56
Subject: Re: Implicit cast of literal in SQL statements
Previous:From: Tom LaneDate: 2001-12-27 14:49:50
Subject: Re: Serializable access giving wrong error messages?

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