Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsqlfunction - Mailing list pgsql-bugs

From Pavel Stehule
Subject Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsqlfunction
Date
Msg-id 162867790909070647k18d7024dh53497a040edb7055@mail.gmail.com
Whole thread Raw
In response to Odp: Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsqlfunction  ("Tomasz Karlik" <Tomasz.Karlik@ultimo.pl>)
Responses Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsqlfunction  (Pavel Stehule <pavel.stehule@gmail.com>)
Odp: Re: Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsqlfunction  ("Tomasz Karlik" <Tomasz.Karlik@ultimo.pl>)
List pgsql-bugs
Hello

2009/9/7 Tomasz Karlik <Tomasz.Karlik@ultimo.pl>:
>
>
>>>> Alvaro Herrera <alvherre@commandprompt.com> 9/4/2009 7:23 PM >>>
> tkarlik@ultimo.pl wrote:
>
>> Without casting function executes much slower:
>>
>> CREATE OR REPLACE FUNCTION table_exists(tblname text) RETURNS boolean AS=
 '
>> DECLARE
>> exists boolean;
>> BEGIN
>>=C2=A0=C2=A0=C2=A0=C2=A0 SELECT 1 INTO exists FROM pg_class WHERE relname=
 =3D name($1);
>>=C2=A0=C2=A0=C2=A0=C2=A0 RETURN exists;
>> END;
>> ' LANGUAGE 'plpgsql' IMMUTABLE;
>

it some strange. What version do you use?

on 5.4

postgres=3D# explain select * from pg_class where relname=3D'aaa';
                                         QUERY PLAN

---------------------------------------------------------------------------=
-----
-------------
 Index Scan using pg_class_relname_nsp_index on pg_class  (cost=3D0.00..8.2=
7 rows=3D
1 width=3D185)
   Index Cond: (relname =3D 'aaa'::name)
(2 rows)

the casting is implicit.

regards
Pavel Stehule

> If you're looking for a speedy answer, try a SQL function, not plpgsql.
>
>
> The same issue when using SQL function... However other casting (for exam=
ple
> int4->int8) works properly.
>

pgsql-bugs by date:

Previous
From: "Tomasz Karlik"
Date:
Subject: Odp: Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsqlfunction
Next
From: Pavel Stehule
Date:
Subject: Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsqlfunction