Different cast behavior of TEXT and VARCHAR

From: tomas(at)tuxteam(dot)de
To: pgsql-general(at)postgresql(dot)org
Subject: Different cast behavior of TEXT and VARCHAR
Date: 2011-04-12 06:36:04
Message-ID: 20110412063604.GA13404@tomas
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

When PREPARing statements, the type guessing machinery seems to behave
differently for VARCHAR and TEXT. Is this intentional?

This is all against PostgreSQL 8.4.5

Illustration:

| tomas(at)floh:~$ psql foo
=> psql (8.4.5)
=> Type "help" for help.
|
| foo=# CREATE TABLE bar (
| foo(# a TEXT,
| foo(# b VARCHAR
| foo(# );
=> CREATE TABLE
| foo=# PREPARE s1 AS SELECT a, b FROM BAR WHERE a = $1;
=> PREPARE
| foo=# PREPARE s1 AS SELECT a, b FROM BAR WHERE b = $1;
=> ERROR: could not determine data type of parameter $1

In the case of VARCHAR, I get no error if I put the placeholder in
quotes (i.e. '$1').

It's no big issue for me. I'll just switch to TEXT anyway, but it's a
bit surprising :-)

Thanks for any insights

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFNo/LUBcgs9XrR2kYRAtYVAJ4wpms/EuAhlfDmH2xKIgeFJWRS9wCfeBsY
ZdlA/GaNrFS4DAyekNlH0hM=
=cmap
-----END PGP SIGNATURE-----

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-04-12 06:59:25 Re: what data type to store fixed size integer?
Previous Message Uwe Schroeder 2011-04-12 05:58:01 Re: Why is 8.4 and 9.0 so much slower on some queries?