Précédent   Forum des professionnels en informatique > Bases de données > PostgreSQL
PostgreSQL Forum PostgreSQL. Avant de poster -> F.A.Q PostGreSQL Tutoriels PostGreSQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/10/2006, 17h17   #1
Invité de passage
 
Inscription : octobre 2006
Messages : 13
Détails du profil
Informations forums :
Inscription : octobre 2006
Messages : 13
Points : 2
Points : 2
Par défaut Problème dans une fonction

Bonjours,

Je doit ajouter dans une table (qui correspond aux noeuds d'un graphe) les coordonnées de départ d'une arrete correspondante.
L'idée générale a été posée, mais j'ai une erreur dans la condition IF qui suit :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
CREATE OR REPLACE FUNCTION map3d_geom2node(table_geom character varying, table_node character varying) RETURNS void AS
$$
	DECLARE
 
		row_node_modify record;
		row_edge_to_node record;
 
	BEGIN
 
		-- If the column the geom do not exist on table_node, it must be added
		IF NOT EXISTS(SELECT the_geom FROM table_node DESC LIMIT 1) THEN
			EXECUTE 'SELECT AddGeometryColumn(' || quote_ident() || ', ' || quote_ident(table_node) || ',' || quote_ident(the_geom) || ',' || quote_ident(-1) || ',' || quote_ident(POINT) || ',2);' 
		END IF;
 
		-- for each table_node row, we get the starting point of the edge
		FOR row_node_modify IN EXECUTE 'SELECT * FROM ' || quote_ident(table_from) LOOP
				EXECUTE 'SELECT INTO row_edge_to_node startPoint(geometryN(the_geom, 1)) FROM ' || quote_ident(table_geom) || ' WHERE source_id=' || quote_ident(row_node_modify.id) || ' DESC LIMIT 1;'
				EXECUTE 'UPDATE table_node SET the_geom=' || quote_ident(SELECT startPoint(row_edge_to_node.the_geom)) || ' WHERE id=' || quote_ident(row_node_modify.id) || ';';
		END LOOP;
 
	END;
$$
LANGUAGE plpgsql;
Merci de votre aide, cela doit être une petite erreur très bete.
onefootstep est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/11/2006, 09h21   #2
Membre chevronné
 
Avatar de gerald2545
 
Inscription : février 2003
Messages : 643
Détails du profil
Informations forums :
Inscription : février 2003
Messages : 643
Points : 660
Points : 660
et c'est quoi l'erreur?
ton premier quote_ident() ne contient rien, c'est normal?
gerald2545 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/11/2006, 09h46   #3
Invité de passage
 
Inscription : octobre 2006
Messages : 13
Détails du profil
Informations forums :
Inscription : octobre 2006
Messages : 13
Points : 2
Points : 2
Voilà une version un peu plus correcte mais qui ne marche toujours pas.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
CREATE OR REPLACE FUNCTION map3d_geom2node(table_geom character varying, table_node character varying) RETURNS void AS
$body$
	DECLARE
	 	test record;
		row_node_modify record;
		row_edge_to_node record;
		start_point geometry;
		geom character varying;
 
	BEGIN 
		-- Test l'existance de la colonne the_geom, ajout si elle exist pas
		IF NOT EXISTS(SELECT * FROM information_schema.COLUMNS WHERE column_name='the_geom' AND table_name=table_node) THEN
			EXECUTE 'SELECT AddGeometryColumn(\'\',\'' || quote_ident(table_node) || '\', \'the_geom\', \'-1\', \'MULTIPOINT\',2)'; 
		END IF;
 
		FOR row_node_modify IN EXECUTE 'SELECT * FROM ' || quote_ident(table_node) LOOP
			SELECT * INTO row_edge_to_node FROM table_geom WHERE source_id=row_node_modify.id LIMIT 1;
			geom := startPoint(geometryN(the_geom,1));
			EXECUTE 'UPDATE ' || quote_ident(table_node) || ' SET the_geom=' || geom || ' WHERE id=' || row_node_modify.id;
		END LOOP;
 
	END;
$body$
LANGUAGE 'plpgsql' VOLATILE STRICT;
Code d'erreur
Code :
1
2
3
4
5
6
D:\Share\SQL>psql -f add_geom2node.psql test
psql:add_geom2node.psql:31: ERREUR:  erreur de syntaxe sur ou prÞs de ½$1+ au caractÞre 17
REQU-TE : SELECT  * FROM  $1  WHERE source_id= $2  LIMIT 1
CONTEXTE : SQL statement IN PL/PgSQL FUNCTION "map3d_geom2node" near line 15
psql:add_geom2node.psql:31: LIGNE 1 : SELECT  * FROM  $1  WHERE source_id= $2  LIMIT 1
psql:add_geom2node.psql:31:
onefootstep est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 18h22.


 
 
 
 
Partenaires

Hébergement Web