Typecasting in SQL functions

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

Typecasting in SQL functions

От:
Konstantinos Vassiliadis <vassilik@p22.cs.man.ac.uk>
Дата:
Hi,
I have the following
 
create table reference
(author text,
 journal text);

create table subref
 (ref reference);

I want to insert a tuple into relation 'subref'. I spotted in the mailing
list that Nicolas Caillaud created a function to insert values to his
relation 'book' so I thought I tried the same 

create function add_ref(text,text) returns reference
 as 'select * from reference  
     where author=$1 and journal=$2'
 language 'sql';

I get the following
 ERROR:  There is no operator '=$' for types 'text' and 'int4'
        You will either have to retype this query using an explicit cast,
        or you will have to define the operator using CREATE OPERATOR

Obviously it confuses author=$1...
I have looked at the documenation (Ch 4. 'Extending SQL Functions'
PostgreSQL Programmer's Guide) where they typecast for the function
new_emp().

I have tried 
  
  where author=::$1...

and get the same error message.

Can somebody help me on typecasting?

Kostas Vassiliadis


Re: [SQL] Typecasting in SQL functions

От:
Zsolt Varga <redax@agria.hu>
Дата:
On Tue, 14 Jul 1998, Konstantinos Vassiliadis wrote:

|Hi,
|I have the following
| 
|create table reference
|(author text,
| journal text);
|
|create table subref
| (ref reference);

	what it means when a field type another table
	???

	what the reason for it?

	redax

.----------------------------------------------------------.
|Zsolt Varga            | tel/fax:   +36 36 422811         |
| AgriaComputer LTD     | email:     redax@agria.hu        |
| System Administrator  | URL:       http://www.agria.hu/  |
`----------------------------------------------------------'

FAQ