0

I have a windows (10 pro) powershell script that reads messages from an external server and INSERTS them into a postges (v10.5) database table.

The table has an AFTER INSERT trigger defined on on it which includes some RAISE NOTICE statements to generate simple messages. If I manually insert a single record using pgAdmin then I can see the RAISE NOTICE in the 'messages' tab.

Where do the trigger messages go when inserting into the same table from a powershell script? How can I make the messages from the trigger appear in the powershell console window?

UPDATE - Database connection is made like this:-

$DBConnectionString = "Driver={PostgreSQL UNICODE(x64)};Server=$MyServer;Port=$MyPort;Database=$MyDB;Uid=$MyUid;Pwd=$MyPass;Options='autocommit=off';"
$DBConn = New-Object System.Data.Odbc.OdbcConnection;
$DBConn.ConnectionString = $DBConnectionString;
$DBConn.Open();

and the insert is issued like this...

$insertDml3 = "INSERT INTO Message(rawMessage, loadedTime) VALUES ('$strLine',to_timestamp('$loadDate','DD-Mon-YYYY HH24:MI:SS'))"
$DBCmd = $DBConn.CreateCommand();
$DBCmd.CommandText = $insertDml3;
$DBCmd.ExecuteReader();
2
  • How are you invoking PostgreSQL from the powershell? Via psql? Aug 30 '19 at 10:25
  • This is probably a better question for a different stackexchange (maybe superuser?) You probably have to do something magical and mysterious with OdbcInfoMessageEventHandler (docs.microsoft.com/en-us/dotnet/api/…).
    – jjanes
    Aug 30 '19 at 12:31

Your Answer

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

Browse other questions tagged or ask your own question.