Dynamic SQL Syntax help please
| От | Ruben Gouveia |
|---|---|
| Тема | Dynamic SQL Syntax help please |
| Дата | |
| Msg-id | 51e507b0809041341j7cf576b6s8895a01d2b14a519@mail.gmail.com обсуждение |
| Ответы |
Re: Dynamic SQL Syntax help please
|
| Список | pgsql-sql |
I created a simple function that i want to use another function (in the same schema) that will be used to create a sql statement. I get the following error when i try this:
ERROR: syntax error at or near "EXEC" at character 1
QUERY: EXEC SQL EXECUTE $1 INTO $2
CONTEXT: SQL statement in PL/PgSQL function "fcn_population" near line 10
********** Error **********
ERROR: syntax error at or near "EXEC"
SQL state: 42601
Context: SQL statement in PL/PgSQL function "fcn_population" near line 10
Here is my function:
CREATE OR REPLACE FUNCTION fcn_population(p_date date, p_where varchar)
RETURNS numeric AS $$
DECLARE
v_total_pop numeric := 0;
v_stmt varchar(1024);
v_where varchar(256) := 'where m.date_created < '||p_date||' '||+ integer '1'||' ';
BEGIN
v_stmt := fcn_gen_statement(p_type, v_where, 0);
EXEC SQL EXECUTE v_stmt INTO v_total_pop;
return v_total_pop;
END;
$$ LANGUAGE plpgsql;
ERROR: syntax error at or near "EXEC" at character 1
QUERY: EXEC SQL EXECUTE $1 INTO $2
CONTEXT: SQL statement in PL/PgSQL function "fcn_population" near line 10
********** Error **********
ERROR: syntax error at or near "EXEC"
SQL state: 42601
Context: SQL statement in PL/PgSQL function "fcn_population" near line 10
Here is my function:
CREATE OR REPLACE FUNCTION fcn_population(p_date date, p_where varchar)
RETURNS numeric AS $$
DECLARE
v_total_pop numeric := 0;
v_stmt varchar(1024);
v_where varchar(256) := 'where m.date_created < '||p_date||' '||+ integer '1'||' ';
BEGIN
v_stmt := fcn_gen_statement(p_type, v_where, 0);
EXEC SQL EXECUTE v_stmt INTO v_total_pop;
return v_total_pop;
END;
$$ LANGUAGE plpgsql;
В списке pgsql-sql по дате отправления: