function does not exist error...

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

function does not exist error...

От:
Dan Jewett <danjewett@mac.com>
Дата:
Can someone help me figure out why my trigger can't meet my function? 
Other than the obvious reason that I'm a total beginner, and I don't 
know what the heck I'm doing. :-)

After I got the CreateTrigger error, I reran the CreateFunction query 
just to see what would happen:

recordings=> CREATE FUNCTION check_participant(varchar) RETURNS opaque AS '
	DECLARE name ALIAS FOR $1;
	BEGIN
	SELECT fname FROM participant WHERE fname = name; IF FOUND 
THEN RETURN 0;
	ELSE INSERT INTO artist (fname) VALUES (name); END IF; END;' 
LANGUAGE 'plpgsql';

ERROR:  function check_participant already exists with same argument types

recordings=> CREATE TRIGGER trigger_artist BEFORE INSERT ON participant
	FOR EACH ROW EXECUTE PROCEDURE check_participant();

ERROR:  CreateTrigger: function check_participant() does not exist

Re: function does not exist error...

От:
"Josh Berkus" <josh@agliodbs.com>
Дата:
Dan,

> Can someone help me figure out why my trigger can't meet my function?
> Other than the obvious reason that I'm a total beginner, and I don't
> know what the heck I'm doing. :-)

Welcome to the NOVICE list, then.

> 
> After I got the CreateTrigger error, I reran the CreateFunction query
> just to see what would happen:
> 
> recordings=> CREATE FUNCTION check_participant(varchar) RETURNS
> opaque AS '

Here's your problem; you've created a function with a varchar parameter
...

> ERROR:  CreateTrigger: function check_participant() does not exist

... and you're then calling it with no parameters.  check_participant()
and check_participant('some string') are two different functions, as
would be check_participant(Numeric, Int) if you created it.

However, the function you have is otherwise inappropriate; it returns
values to the screen (not possible with a trigger), takes a parameter,
and does not return NEW.   What are you trying to do, exactly?

-Josh Berkus

Re: function does not exist error...

От:
Dan Jewett <danjewett@mac.com>
Дата:
>Dan,
>
>>  Can someone help me figure out why my trigger can't meet my function?
>>  Other than the obvious reason that I'm a total beginner, and I don't
>>  know what the heck I'm doing. :-)
>
>Welcome to the NOVICE list, then.
>
>>
>>  After I got the CreateTrigger error, I reran the CreateFunction query
>>  just to see what would happen:
>>
>>  recordings=> CREATE FUNCTION check_participant(varchar) RETURNS
>>  opaque AS '
>
>Here's your problem; you've created a function with a varchar parameter
>...
>
>>  ERROR:  CreateTrigger: function check_participant() does not exist
>
>... and you're then calling it with no parameters.  check_participant()
>and check_participant('some string') are two different functions, as
>would be check_participant(Numeric, Int) if you created it.
>
>However, the function you have is otherwise inappropriate; it returns
>values to the screen (not possible with a trigger), takes a parameter,
>and does not return NEW.   What are you trying to do, exactly?
>
>-Josh Berkus

Josh, Thanks for your response.

The big picture of what I'm trying to do is that I have large flat 
file of records created with info about individual recordings 
(songs).  I want to split those out into appropriately referenced 
tables.

I thought I could create a combination of rules and triggers to step 
through the table (or a text file exported from it) and send the data 
where it needs to go.  Part of the process would be to check for 
existing entries to prevent redundency. I also want be able to add 
entries to join tables on the fly.

I'm obviously not getting some of the basics of this process, and 
having trouble with syntax.  So it looks like I'm going to have to 
back up a bit.

Thanks for the info on the functions,
Dan


If you are remotely interested...
Below is the draft of the table set I want to work with.  It makes 
sense if a "performance" record is understood as an instance of a 
participant on a recording, and if "track" is understood as an 
instance of a recording on an album.

BEGIN;

CREATE TABLE album
(
	album_id SERIAL PRIMARY KEY,
	catalog_id VARCHAR,
	title VARCHAR,
	media VARCHAR,
	release_date VARCHAR,
	notes TEXT
);

SELECT setval('album_album_id_seq', 1000);

CREATE TABLE recording
(
	recording_id SERIAL PRIMARY KEY,
	title VARCHAR,
	date VARCHAR,
	genre VARCHAR,
	path VARCHAR,
	notes TEXT
);

SELECT setval('recording_recording_id_seq', 1000);

CREATE TABLE track		--join table on recording-album
(
	track_id SERIAL PRIMARY KEY,
	recording_id INT REFERENCES recording,
	album_id INT REFERENCES album,
	track_no INT,
	track_length INTERVAL
);

SELECT setval('track_track_id_seq', 1000);

CREATE TABLE participant
(
	participant_id SERIAL PRIMARY KEY,
	fname VARCHAR,
	lname VARCHAR,
	mname VARCHAR,
	nick VARCHAR,
	birth DATE,
	death DATE,
	blocation VARCHAR,
	dlocation VARCHAR,
	notes TEXT
);

SELECT setval('participant_personal_id_seq', 1000);

CREATE TABLE performance  --join table on recording-participant
(
	performance_id SERIAL PRIMARY KEY,
	recording_id INT REFERENCES recording,
	participant_id INT REFERENCES participant,
	role VARCHAR
);

SELECT setval('performance_performance_id_seq', 1000);

COMMIT;

Re: function does not exist error...

От:
Josh Berkus <josh@agliodbs.com>
Дата:

Dan,

> The big picture of what I'm trying to do is that I have large flat 
> file of records created with info about individual recordings 
> (songs).  I want to split those out into appropriately referenced 
> tables.
> 
> I thought I could create a combination of rules and triggers to step 
> through the table (or a text file exported from it) and send the data 
> where it needs to go.  Part of the process would be to check for 
> existing entries to prevent redundency. I also want be able to add 
> entries to join tables on the fly.

Why do you want to use Triggers and Rules?   Do you need to import this data 
from source daily?  Even so, batch processing will be faster than executing a 
trigger for each row inserted.

-- 
-Josh Berkus

______AGLIO DATABASE SOLUTIONS___________________________
                                        Josh Berkus
   Complete information technology 	josh@agliodbs.com
    and data management solutions 	(415) 565-7293
   for law firms, small businesses 	 fax 621-2533
    and non-profit organizations. 	San Francisco

Re: function does not exist error...

От:
Dan Jewett <danjewett@mac.com>
Дата:
>Dan,
>
>>  The big picture of what I'm trying to do is that I have large flat
>>  file of records created with info about individual recordings
>>  (songs).  I want to split those out into appropriately referenced
>>  tables.
>>
>>  I thought I could create a combination of rules and triggers to step
>>  through the table (or a text file exported from it) and send the data
>>  where it needs to go.  Part of the process would be to check for
>>  existing entries to prevent redundency. I also want be able to add
>>  entries to join tables on the fly.
>
>Why do you want to use Triggers and Rules?   Do you need to import this data
>from source daily?  Even so, batch processing will be faster than executing a
>trigger for each row inserted.
>
>--
>-Josh Berkus

You are right of course.  Thanks for rearranging my thinking on this. 
So, on to figuring out the query for the batch.

Dan
FAQ