Unix Technical Forum

Where is the error

This is a discussion on Where is the error within the Pgsql General forums, part of the PostgreSQL category; --> Hi I have the following function: CREATE OR REPLACE FUNCTION "int" (boolean) RETURNS integer AS' select CASE WHEN $1 ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 06:35 PM
Kaloyan Iliev Iliev
 
Posts: n/a
Default Where is the error

Hi
I have the following function:

CREATE OR REPLACE FUNCTION "int" (boolean) RETURNS integer AS'
select CASE WHEN $1 THEN 1
ELSE 0
END
'LANGUAGE 'sql';

When I try to use it:

select int('t'::bool);
ERROR: syntax error at or near "(" at character 11

I am using PG8.0b1

Thank you.

Kaloyan



---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 06:35 PM
Andreas Kretschmer
 
Posts: n/a
Default Re: Where is the error

begin Kaloyan Iliev Iliev <news1@faith.digsys.bg> wrote:
> Hi
> I have the following function:


> CREATE OR REPLACE FUNCTION "int" (boolean) RETURNS integer AS'


I'm not sure. But 'int' is reserved, possibly is this the error.

CREATE OR REPLACE FUNCTION my_int (boolean) RETURNS integer AS'
select CASE WHEN $1 THEN 1
ELSE 0
END
'LANGUAGE 'sql';

test_db=# select my_int('t'::bool);
my_int
--------
1
(1 Zeile)



end
Regards, Andreas
--
Diese Message wurde erstellt mit freundlicher Unterstützung eines freilau-
fenden Pinguins aus artgerechter Freilandhaltung. Er ist garantiert frei
von Micro$oft'schen Viren. (#97922 http://counter.li.org) GPG 7F4584DA
Was, Sie wissen nicht, wo Kaufbach ist? Hier: N 51.05082°, E 13.56889° ;-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 06:36 PM
John DeSoi
 
Posts: n/a
Default Re: Where is the error


On Dec 27, 2004, at 6:42 AM, Kaloyan Iliev Iliev wrote:

> CREATE OR REPLACE FUNCTION "int" (boolean) RETURNS integer AS'
> select CASE WHEN $1 THEN 1
> ELSE 0
> END
> 'LANGUAGE 'sql';
>


The problem is that you have quoted the function name as "int". You
should only do this when you want to force the exact case of the name.
When you do it this way, you have to use double quotes when you refer
to the identifier:


select "int"('t'::boolean);
int
-----
1
(1 row)


So in this case you probably want to call your function int -- without
quotes. By default, PostgreSQL folds the names to lowercase.


Best,

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 06:36 PM
Kaloyan Iliev Iliev
 
Posts: n/a
Default Re: Where is the error

10x John,

You are right.The problem is that the function was dumped with quotes
from pg_dump but I suppose the one who created it used quotes and that's
why it dumps in this way.
I will fix this in the dump.

Thanks again.

Kaloyan

John DeSoi wrote:

>
> On Dec 27, 2004, at 6:42 AM, Kaloyan Iliev Iliev wrote:
>
>> CREATE OR REPLACE FUNCTION "int" (boolean) RETURNS integer AS'
>> select CASE WHEN $1 THEN 1
>> ELSE 0
>> END
>> 'LANGUAGE 'sql';
>>

>
> The problem is that you have quoted the function name as "int". You
> should only do this when you want to force the exact case of the name.
> When you do it this way, you have to use double quotes when you refer
> to the identifier:
>
>
> select "int"('t'::boolean);
> int
> -----
> 1
> (1 row)
>
>
> So in this case you probably want to call your function int -- without
> quotes. By default, PostgreSQL folds the names to lowercase.
>
>
> Best,
>
> John DeSoi, Ph.D.
> http://pgedit.com/
> Power Tools for PostgreSQL
>
>


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-08-2008, 06:36 PM
Marek Lewczuk
 
Posts: n/a
Default Re: Where is the error

Kaloyan Iliev Iliev napisał(a):
> Hi
> I have the following function:
>
> select int('t'::bool);
> ERROR: syntax error at or near "(" at character 11
>

"int" is reserved for integer type, so you should not use it. However if
you add
namespace before function name "public.int(TRUE)" then it should work.

ML




---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-08-2008, 06:36 PM
Kaloyan Iliev Iliev
 
Posts: n/a
Default Re: Where is the error

Hi again,

When I chage in the dump file

CREATE FUNCTION int (boolean) RETURNS integer AS '
select CASE WHEN $1 THEN 1
ELSE 0
END ' LANGUAGE sql;

ERROR: syntax error at or near "(" at character 21

I receive this message. So the question is how to create it without quotes.

Thank in advance


Kaloyan


John DeSoi wrote:

>
> On Dec 27, 2004, at 6:42 AM, Kaloyan Iliev Iliev wrote:
>
>> CREATE OR REPLACE FUNCTION "int" (boolean) RETURNS integer AS'
>> select CASE WHEN $1 THEN 1
>> ELSE 0
>> END
>> 'LANGUAGE 'sql';
>>

>
> The problem is that you have quoted the function name as "int". You
> should only do this when you want to force the exact case of the name.
> When you do it this way, you have to use double quotes when you refer
> to the identifier:
>
>
> select "int"('t'::boolean);
> int
> -----
> 1
> (1 row)
>
>
> So in this case you probably want to call your function int -- without
> quotes. By default, PostgreSQL folds the names to lowercase.
>
>
> Best,
>
> John DeSoi, Ph.D.
> http://pgedit.com/
> Power Tools for PostgreSQL
>
>


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-08-2008, 06:36 PM
Kaloyan Iliev Iliev
 
Posts: n/a
Default Re: Where is the error

Thanks To you all.

The problem was that the int was reserved. When I try

CREATE FUNCTION my_int(boolean) RETURNS integer AS '
select CASE WHEN $1 THEN 1
ELSE 0
END ' LANGUAGE sql;

it worked.

But now I have to change it on many places. This is not good beacause on
the old version of PG (form where I dumped) everithing was OK

Kaloyan

Kaloyan Iliev Iliev wrote:

> Hi
> I have the following function:
>
> CREATE OR REPLACE FUNCTION "int" (boolean) RETURNS integer AS'
> select CASE WHEN $1 THEN 1
> ELSE 0
> END
> 'LANGUAGE 'sql';
>
> When I try to use it:
>
> select int('t'::bool);
> ERROR: syntax error at or near "(" at character 11
>
> I am using PG8.0b1
>
> Thank you.
>
> Kaloyan
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>
>


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:32 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com