weird cast behavior in "IN (values)" clause

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: weird cast behavior in "IN (values)" clause
Date: 2011-07-06 02:10:23
Message-ID: 1309918036-sup-4092@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I just came across this:

alvherre=# select * from pg_class where oid::regclass in ('foo');
ERROR: invalid input syntax for type oid: "foo"
LÍNEA 1: select * from pg_class where oid::regclass in ('foo');
^
alvherre=# select * from pg_class where oid::regclass in ('foo', 'foo');
relname | relnamespace | reltype | reloftype | relowner | relam | relfilenode | reltablespace | relpages | reltuples | reltoastrelid | reltoastidxid | relhasindex | relisshared | relpersistence | relkind | relnatts | relchecks | relhasoids | relhaspkey | relhasrules | relhastriggers | relhassubclass | relfrozenxid | relacl | reloptions
---------+--------------+---------+-----------+----------+-------+-------------+---------------+----------+-----------+---------------+---------------+-------------+-------------+----------------+---------+----------+-----------+------------+------------+-------------+----------------+----------------+--------------+--------+------------
foo | 2200 | 16448 | 0 | 10 | 0 | 16446 | 0 | 0 | 0 | 0 | 0 | t | f | p | r | 1 | 0 | f | t | f | f | f | 720 | |
(1 fila)

Not sure what to make of it.

(The reason I put the regclass cast in the oid instead of the other way
around is that I was trying a bunch of other tables, so it was
oid::regclass IN ('foo', 'bar', 'baz')
which is a lot easier to type than attaching a regclass cast to each
literal).

I am not sure why it would be valid to list two literals in the values
but not one.

--
Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-07-06 04:24:09 Re: weird cast behavior in "IN (values)" clause
Previous Message Alvaro Herrera 2011-07-06 01:26:28 Re: Potential NULL dereference found in typecmds.c