Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Postgresql DBLink Error
Message
From
02/09/2022 15:56:23
 
 
To
02/09/2022 08:39:06
General information
Forum:
PostgreSQL
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01684928
Message ID:
01684929
Views:
50
>Good norning,
>I'm testing how to insert data into another postgresq database and I'm having the attached error.
>Below is the code to create the postgresql function:
>
>
>CREATE OR REPLACE FUNCTION efaturas(
> character,
>character,
> character,
> character)
> RETURNS text AS
> $BODY$
>
> DECLARE
>
>o_codigo_retorno character(5);
>a_data_vencimento date;
> lcComandoSQL text;
>o_tipodoc character(2);
>o_totaldocumento numeric(10,2);
>
>BEGIN
> -- Reuno as Variaveis
> o_tipodoc := $4;'
>o_totaldocumento := 15000;
>
> lcComandoSQL := 'INSERT INTO teste(nomeentidade, valor) VALUES('||o_tipodoc||', '||o_totaldocumento||')';
> -- Gravo os Dados no ficheiro de Documentos na Base dados eFatura
>SELECT * FROM dblink('dbname = mydb port = 5432 host = myserver.com user = my_login password = 1234', lcComandoSQL) AS foreign_rec(id integer) INTO o_codigo_retorno;
>
> END;$BODY$
> LANGUAGE plpgsql VOLATILE
> COST 100;
> ALTER FUNCTION efaturas(character, character, character, character)
> OWNER TO clima_user;

According to the ODBC error, your query is referencing a column named "fr" which does not exist:

- Can you print or debug the literal value of your "lcComandoSQL" string before you try to execute it?
- This is a guess, but you may need spaces after "teste" and "VALUES" in the query i.e.
lcComandoSQL := 'INSERT INTO teste (nomeentidade, valor) VALUES ('||o_tipodoc||', '||o_totaldocumento||')';
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform