psql

Display select results vertically in psql, as is done by MySQL's \G

[亡魂溺海] 提交于 2019-11-27 10:25:04
问题 In MySQL, you can terminate a select query with \G (as opposed to \g ) to display the results vertically: select * from foo \G *************** id: 1 bar: Hello *************** id: 2 bar: World How can one do the same thing for PostgreSQL using psql? 回答1: You can do this by enabling Expanded display . Toggle this setting via \x . For example: # \x Expanded display is on. # \x Expanded display is off. When on, results are shown in tabular (vertical) form: -[ RECORD 1 ] id | 1 bar | Hello -[

How can I connect to a postgreSQL database into Apache Spark using scala?

隐身守侯 提交于 2019-11-27 10:20:03
I want to know how can I do following things in scala? Connect to a postgreSQL database using Spark scala. Write SQL queries like SELECT , UPDATE etc. to modify a table in that database. I know to do it using scala but how to import the connector jar of psql scala into sbt while packaging it? Our goal is to run parallel SQL queries from the Spark workers. Build setup Add the connector and JDBC to the libraryDependencies in build.sbt . I've only tried this with MySQL, so I'll use that in my examples, but Postgres should be much the same. libraryDependencies ++= Seq( jdbc, "mysql" % "mysql

How to exit from PostgreSQL command line utility: psql

こ雲淡風輕ζ 提交于 2019-11-27 09:55:31
What command or short key can I use to exit the PostgreSQL command line utility psql ? Type \q and then press ENTER to quit psql . UPDATE: 19-OCT-2018 As of PostgreSQL 11 , the keywords " quit " and " exit " in the PostgreSQL command-line interface have been included to help make it easier to leave the command-line tool. My usual key sequence is: quit() quit exit() exit q q() !q ^C help Alt + Tab google.com Quit PSQL \q I think veterans of the psql command line usually shorten that to just: \q Kaarel Ctrl + D is what I usually use to exit psql console. Try: Ctrl + Z - this sends the TSTP

Postgresql not creating db with “createdb” as superuser, yet not outputting errors

旧城冷巷雨未停 提交于 2019-11-27 09:42:55
问题 I am working with a fresh postgresql install, with 'postgres' super user. Logged in via: sudo -u postgres psql postgres=# createdb database postgres-# \list List of databases Name | Owner | Encoding | Collation | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | template0 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres : postgres=CTc/postgres template1 | postgres

postgresql port confusion 5433 or 5432?

北战南征 提交于 2019-11-27 09:26:58
问题 I have installed postgresql on OSX. When I run psql, I get $ psql psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5433"? However, from /etc/services postgresql 5432/udp # PostgreSQL Database postgresql 5432/tcp # PostgreSQL Database # Tom Lane <tgl@sss.pgh.pa.us> pyrrho 5433/tcp # Pyrrho DBMS pyrrho 5433/udp # Pyrrho DBMS 5433 is occupied by pyrrho, 5432 is assigned to pg. I can connect

Using psql how do I list extensions installed in a database?

主宰稳场 提交于 2019-11-27 09:20:11
问题 How do I list all extensions that are already installed in a database or schema from psql? See also Finding a list of available extensions that PostgreSQL ships with 回答1: In psql that would be \dx See the manual for details: http://www.postgresql.org/docs/current/static/app-psql.html Doing it in plain SQL it would be a select on pg_extension : SELECT * FROM pg_extension http://www.postgresql.org/docs/current/static/catalog-pg-extension.html 回答2: Additionally if you want to know which

PSQL Command Line Arguments in DO script

左心房为你撑大大i 提交于 2019-11-27 07:27:05
问题 I've got a script NewSchemaSafe.sql that creates a new schema based on the project directory; it's called from the Windows command line as follows: for %%a in (.) do set this=%%~na -- other stuff here psql -U postgres -d SLSM -e -v v1=%this% -f "NewSchemaSafe.sql" NewSchemaSafe.sql is as follows: -- NewSchemaSafe.sql -- NEW SCHEMA SETUP -- - checks if schema exists -- - if yes, renames existing with current monthyear as suffix -- NOTE: will always delete any schema with the 'rename' name

PostgreSQL: encoding problems on Windows when using psql command line utility

隐身守侯 提交于 2019-11-27 06:46:09
I'm working in a centralized monitoring system on Windows 2008 R2, I have installed a PostgreSQL 9.3 to use psql from the command line. When I try to access to some remote Postgres (an 8.4 in my principal case) I have an error with the encoding: command: psql.exe -h 192.168.114.12 -p 5432 -d db_seros_transaccion -U postgres -f script.sql error: psql: FATAL: la conversión entre WIN1252 y LATIN1 no está soportada I try adding the sentence SET client_encoding = 'UTF8'; in my script but the problem persist (and with other encodings too, like LATIN1 & WIN1252). After googling it I found people that

How to switch databases in psql?

泄露秘密 提交于 2019-11-27 05:44:02
In MySQL I used use database_name; What's the psql equivalent? Will Hartung In PostgreSQL, you can use the \connect meta-command of the client tool psql: \connect DBNAME or in short: \c DBNAME meagar You can connect to a database with \c <database> or \connect <database> . At the PSQL prompt, you can do: \connect (or \c) dbname Jeswin K Ninan You can connect using \c dbname You can select the database when connecting with psql. This is handy when using it from a script: sudo -u postgres psql -c "CREATE SCHEMA test AUTHORIZATION test;" test Using psql's meta-command \c or \connect [ dbname [

Run a PostgreSQL .sql file using command line arguments

倖福魔咒の 提交于 2019-11-27 05:43:57
I have some .sql files with thousands of INSERT statements in them and need to run these inserts on my PostgreSQL database in order to add them to a table. The files are that large that it is impossible to open them and copy the INSERT statements into an editor window and run them there. I found on the Internet that you can use the following by navigating to the bin folder of your PostgreSQL install: psql -d myDataBase -a -f myInsertFile In my case: psql -d HIGHWAYS -a -f CLUSTER_1000M.sql I am then asked for a password for my user, but I cannot enter anything and when I hit enter I get this