dynamic sql query in postgres

EXECUTE … USING only works in PL/PgSQL – ie within functions or DO blocks written in the PL/PgSQL language. It does not work in plain SQL; the EXECUTE in plain SQL is completely different, for executing prepared statements. You cannot use dynamic SQL directly in PostgreSQL’s SQL dialect. Compare: PL/PgSQL’s EXECUTE … USING; to SQL’s … Read more

“psql: could not connect to server: Connection refused” Error when connecting to remote database

cd /etc/postgresql/9.x/main/ open file named postgresql.conf sudo vi postgresql.conf add this line to that file listen_addresses=”*” then open file named pg_hba.conf sudo vi pg_hba.conf and add this line to that file host all all 0.0.0.0/0 md5 It allows access to all databases for all users with an encrypted password restart your server sudo /etc/init.d/postgresql restart

Postgresql: Scripting psql execution with password

You may wish to read a summary of the ways to authenticate to PostgreSQL. To answer your question, there are several ways provide a password for password-based authentication: Via the password prompt. Example: psql -h uta.biocommons.org -U foo Password for user foo: In a pgpass file. See libpq-pgpass. Format: <host>:<port>:<database>:<user>:<password> With the PGPASSWORD environment variable. … Read more

What is the format for the PostgreSQL connection string / URL?

If you use Libpq binding for respective language, according to its documentation URI is formed as follows: postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&…] Here are examples from same document postgresql:// postgresql://localhost postgresql://localhost:5432 postgresql://localhost/mydb postgresql://user@localhost postgresql://user:secret@localhost postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp postgresql://localhost/mydb?user=other&password=secret

How to thoroughly purge and reinstall postgresql on ubuntu? [closed]

Option A If your install isn’t already damaged, you can drop unwanted PostgreSQL servers (“clusters”) using pg_dropcluster. Use that in preference to a full purge and reinstall if you just want to restart with a fresh PostgreSQL instance. $ pg_lsclusters Ver Cluster Port Status Owner Data directory Log file 11 main 5432 online postgres /var/lib/postgresql/11/main … Read more