Обсуждение: no implicit cast error in 9.2?

Поиск
Список
Период
Сортировка

no implicit cast error in 9.2?

От
AI Rumman
Дата:
Hi,

I am using
PostgreSQL 9.2.3 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.6
20120305 (Red Hat 4.4.6-4), 64-bit.

I got a bit confused after installing this version. So far I used to know
that from Postgresql 8.3 implicit casting has been removed and the
following should not work at 8.3 :
create table testtab ( id varchar, id1 int)
insert into testtab values (1,1);

Where it was good to work at 8.1

http://osdir.com/ml/pgsql-general/2011-02/msg00055.html

I also faced the problem earlier.

But in 9.2 it is working perfectly.
Am I missing any release notes?

Please share your opinion. It will be appreciated.

Thanks.

Re: no implicit cast error in 9.2?

От
Adrian Klaver
Дата:
On 02/08/2013 12:23 PM, AI Rumman wrote:
> Hi,
>
> I am using
> PostgreSQL 9.2.3 on x86_64-unknown-linux-gnu, compiled by gcc (GCC)
> 4.4.6 20120305 (Red Hat 4.4.6-4), 64-bit.
>
> I got a bit confused after installing this version. So far I used to
> know that from Postgresql 8.3 implicit casting has been removed and the
> following should not work at 8.3 :
> create table testtab ( id varchar, id1 int)
> insert into testtab values (1,1);
>
> Where it was good to work at 8.1
>
> http://osdir.com/ml/pgsql-general/2011-02/msg00055.html
>
> I also faced the problem earlier.
>
> But in 9.2 it is working perfectly.
> Am I missing any release notes?
>
> Please share your opinion. It will be appreciated.

As I remember implicit casting was not entirely removed and the
text <--> int combination was kept.

To extend your example, you can see it works both ways::

test=# create table testtab ( id varchar, id1 int);
CREATE TABLE
test=# insert into testtab values (1,1);
INSERT 0 1
test=# insert into testtab values (1,'1');
INSERT 0 1
test=# SELECT * from testtab ;
  id | id1
----+-----
  1  |   1
  1  |   1
(2 rows)


Unless of course you use a non-integer string:

test=# insert into testtab values (1,'one');
ERROR:  invalid input syntax for integer: "one"
LINE 1: insert into testtab values (1,'one');


>
> Thanks.


--
Adrian Klaver
adrian.klaver@gmail.com

Re: no implicit cast error in 9.2?

От
Kevin Grittner
Дата:
Adrian Klaver <adrian.klaver@gmail.com> wrote:=0A> On 02/08/2013 12:23 PM, =
AI Rumman wrote:=0A=0A>> I got a bit confused after installing this version=
. So far I used to=0A>> know that from Postgresql 8.3 implicit casting has =
been removed and the=0A>> following should not work at 8.3 :=0A>> create ta=
ble testtab ( id varchar, id1 int)=0A>> insert into testtab values (1,1);=
=0A>>=0A>> Where it was good to work at 8.1=0A>>=0A>> http://osdir.com/ml/p=
gsql-general/2011-02/msg00055.html=0A>>=0A>> I also faced the problem earli=
er.=0A>>=0A>> But in 9.2 it is working perfectly.=0A>> Am I missing any rel=
ease notes?=0A>>=0A>> Please share your opinion. It will be appreciated.=0A=
>=0A> As I remember implicit casting was not entirely removed and the=0A> t=
ext <--> int combination was kept.=0A=0AI think it has more to do with reta=
ining (or adding back, I don't=0Arecall) *assignment* casts which aren't su=
pported as *implicit*=0Acasts.=0A=0Atest=3D# select '1'::int =3D '1'::text;=
=0AERROR:=A0 operator does not exist: integer =3D text=0ALINE 1: select '1'=
::int =3D '1'::text;=0A=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 ^=0AHINT:=A0 No operator matches the given name and argu=
ment type(s). You might need to add explicit type casts.=0A=0A-Kevin=0A

Re: no implicit cast error in 9.2?

От
Tom Lane
Дата:
AI Rumman <rummandba@gmail.com> writes:
> I got a bit confused after installing this version. So far I used to know
> that from Postgresql 8.3 implicit casting has been removed and the
> following should not work at 8.3 :
> create table testtab ( id varchar, id1 int)
> insert into testtab values (1,1);

No, that will work fine in any version, because you're calling upon an
assignment cast not an implicit cast.  What once worked and no longer
does is cases like

SELECT length(1);

where the integer argument used to be implicitly cast to text.

            regards, tom lane

Re: no implicit cast error in 9.2?

От
Adrian Klaver
Дата:
On 02/08/2013 01:50 PM, Kevin Grittner wrote:
> Adrian Klaver <adrian.klaver@gmail.com> wrote:
>> On 02/08/2013 12:23 PM, AI Rumman wrote:
>
>>> I got a bit confused after installing this version. So far I used to
>>> know that from Postgresql 8.3 implicit casting has been removed and the
>>> following should not work at 8.3 :
>>> create table testtab ( id varchar, id1 int)
>>> insert into testtab values (1,1);
>>>
>>> Where it was good to work at 8.1
>>>
>>> http://osdir.com/ml/pgsql-general/2011-02/msg00055.html
>>>
>>> I also faced the problem earlier.
>>>
>>> But in 9.2 it is working perfectly.
>>> Am I missing any release notes?
>>>
>>> Please share your opinion. It will be appreciated.
>>
>> As I remember implicit casting was not entirely removed and the
>> text <--> int combination was kept.
>
> I think it has more to do with retaining (or adding back, I don't
> recall) *assignment* casts which aren't supported as *implicit*
> casts.

Ah, so that is the reason. A distinction I missed:(



--
Adrian Klaver
adrian.klaver@gmail.com