1

In oracle I could create .sql files and run them with a structure (like a stored procedure) with

begin

  declare

end;

I did some tests, because I need to run scripts to fix problems, not is necessary record it as a stored procedure/function on server, so like in Oracle, I want to run it once and check the result.

Not is possible run .sql files on postgres with CURSOR, declare, variables, etc.. , only directly on server with stored procedures/functions ?

2

The equivalent of Oracle's anonymous PL/SQL blocks are anonymous PL/pgSQL blocks in Postgres. These are started using the do statement:

do
$$
declare 
  ....
begin
  .... 
end;
$$
  • Another question only...when I ran the .sql, the 'body' of script (between 'do' and 'end') will be printed on my log file, can I avoid it ? I called the script via psql -d database -U user -a -f filepath Here an example of output: i.postimg.cc/hGtqcrx1/screenshot-493.png – MCunha98 Jul 29 at 17:23
  • @MCunha98: psql --quiet? – a_horse_with_no_name Jul 30 at 5:55
  • hmmm...I didn't know this option, I'll do tests, thank again – MCunha98 Jul 30 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.