From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write data to a PostgreSQL database

Hi,

 

I am trying to write some data on LabVIEW and insert it into a local postgreSQL database. I tried to follow the example below (screen shot of example also attached) using format into the string function and system exec.VI:

 

https://decibel.ni.com/content/docs/DOC-30308

 

I get an error message stating:

 

"Error 2 occurred at System Exec.vi. Command was /usr/bin/psql -c "SELECT * FROM test" mydb". Possible reason: LabVIEW memory is full?

 

I am using postgresql 9.6 and LabVIEW 2016.

 

Thanks in advance,

 

Lisa

0 Kudos
Message 1 of 7
(4,791 Views)

It appears that the error code is coming from your Command to read the database.  Have you verified that the database has been installed correctly and it is even possible to execute the Select command?

 

Try going to a command prompt and typing the following:

  • /usr/bin/psql -c "SELECT * FROM demo1" mydb

Did this do something that is "meaningful"?  What do you get from Standard Out and Standard Error?

 

If this works, try "by hand" the other psql commands.  Let us know the results.

 

Bob Schor

Message 2 of 7
(4,756 Views)

Hi thanks for your comment. I managed to get it to execute by finding the actual location of the psql.exe in my c drive. ..

 

C:/Program Files/PostgreSQL/9.6/bin/psql -c "%s" mydb

 

However now the psql.exe pops up asking for a password. Any ideas what this could be? or how to prevent the need for a password?

 

 

 

 

0 Kudos
Message 3 of 7
(4,749 Views)

 

 

0 Kudos
Message 4 of 7
(4,749 Views)

Now you are asking a PostgreSQL question.  Go to their site and see what they say.

 

Bob Schor

0 Kudos
Message 5 of 7
(4,728 Views)

@lisam88 wrote:

Hi thanks for your comment. I managed to get it to execute by finding the actual location of the psql.exe in my c drive. ..

 

C:/Program Files/PostgreSQL/9.6/bin/psql -c "%s" mydb

 

However now the psql.exe pops up asking for a password. Any ideas what this could be? or how to prevent the need for a password?


I would wager there's something like a -p option for providing a password.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 7
(4,708 Views)

 Thanks for your help, it is much appreciated . In the psql guide there are only two options regarding passwords:

  • -w is for when there is no password
  • -W is to prompt for a password.

There is no option to provide the password as a command line argument because that information is often available to all users, and therefore insecure.

I have a password contained in configuration file .pgpass.conf. Perhaps I can put this into the labview code? Would you know how to do this?

0 Kudos
Message 7 of 7
(4,702 Views)