This sounds like it should be a very easy thing to do, however, I cannot find ANYWHERE how to do it.
I have a .sql file I am building for an upgrade to my application that alters tables, inserts/updates, etc.
I want to write to the screen after every command finishes.
So, for instance if I have something like:
insert into X...
I want to see something like,
Starting to insert into table X
Finished inserting into table X
Is this possible in Postgres?
The easiest but the most efficient way to export data from a Postgres table to a CSV file is by using the COPY command. COPY command generates a CSV file on the Database Server. You can export the entire table or the results of a query to a CSV file with the COPY TO command.
To generate SQL scripts from your PostgreSQL project click the SQL Script icon on the main toolbar. New modal opens. Click Save Script and select a location where the file should be stored. Option Overwrite existing files allows you to ignore existing scripts and overwrite them without getting a warning.
To import SQL script file into PostgreSQL database using this tool, take the following steps: Select the database. Navigate to the "SQL" button. Click the "Choose File" (or "Browse") button and select the SQL file from your computer.
If you're just feeding a big pile of SQL to psql
then you have a couple options.
You could run psql
with --echo-all
:
-a
--echo-all
Print all input lines to standard output as they are read. This is more useful for script processing than interactive mode. This is equivalent to setting the variableECHO
toall
.
That and the other "echo everything of this type" options (see the manual) are probably too noisy though. If you just want to print things manually, use \echo
:
\echo
text
[ ... ]
Prints the arguments to the standard output, separated by one space and followed by a newline. This can be useful to intersperse information in the output of scripts.
So you can say:
\echo 'Starting to insert into table X' -- big pile of inserts go here... \echo 'Finished inserting into table X'
There's probably a better way to do it. But if you need to use vanilla SQL, try this:
SELECT NULL AS "Starting to insert into table X"; -- big pile of inserts go here... SELECT NULL AS "Finished inserting into table X";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With