psql

Is there a shortcut for SELECT * FROM?

时光怂恿深爱的人放手 提交于 2019-11-26 20:47:53
There are many useful shortcuts in psql console like \d or \l . I wondering is there one for SELECT * FROM table_name ? I use this query often for learning purposes so it would be quite helpful not to have to write select * from ... all the time. There is a "shortcut" for SELECT * FROM in standard SQL, so you can use it in psql: TABLE tablename; This syntax shorthand can only be used with a limited range of clauses. The manual: It can be used as a top-level command or as a space-saving syntax variant in parts of complex queries. Only the WITH , UNION , INTERSECT , EXCEPT , ORDER BY , LIMIT ,

Alternate output format for psql

♀尐吖头ヾ 提交于 2019-11-26 18:42:22
问题 I am using PostgreSQL 8.4 on Ubuntu. I have a table with columns c1 through cN . The columns are wide enough that selecting all columns causes a row of query results to wrap multiple times. Consequently, the output is hard to read. When the query results constitute just a few rows, it would be convenient if I could view the query results such that each column of each row is on a separate line, e.g. c1: <value of row 1's c1> c2: <value of row 1's c1> ... cN: <value of row 1's cN> ---- some

How to exit from PostgreSQL command line utility: psql

时光总嘲笑我的痴心妄想 提交于 2019-11-26 17:53:13
问题 What command or short key can I use to exit the PostgreSQL command line utility psql ? 回答1: 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. 回答2: 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

Run a PostgreSQL .sql file using command line arguments

早过忘川 提交于 2019-11-26 12:49:01
问题 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

psql: FATAL: database “<user>” does not exist

元气小坏坏 提交于 2019-11-26 12:33:39
问题 I\'m using the PostgreSql app for mac (http://postgresapp.com/). I\'ve used it in the past on other machines but it\'s giving me some trouble when installing on my macbook. I\'ve installed the application and I ran: psql -h localhost It returns: psql: FATAL: database \"<user>\" does not exist It seems I can\'t even run the console to create the database that it\'s attempting to find. The same thing happens when I just run: psql or if I launch psql from the application drop down menu: Machine

dynamic sql query in postgres

断了今生、忘了曾经 提交于 2019-11-26 12:28:26
问题 I was attempting to use Dynamic SQL to run some queries in postgres. Example: EXECUTE format(\'SELECT * from result_%s_table\', quote_ident((select id from ids where condition = some_condition))) I have to query a table, which is of the form result_%s_table wherein, I need to substitute the correct table name (an id) from an another table. I get the error ERROR: prepared statement \"format\" does not exist Link: string substitution with query result postgresql 回答1: EXECUTE ... USING only

How to switch databases in psql?

情到浓时终转凉″ 提交于 2019-11-26 12:16:25
问题 In MySQL I used use database_name; What\'s the psql equivalent? 回答1: In PostgreSQL, you can use the \connect meta-command of the client tool psql: \connect DBNAME or in short: \c DBNAME 回答2: You can connect to a database with \c <database> or \connect <database> . 回答3: At the PSQL prompt, you can do: \connect (or \c) dbname 回答4: 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;"

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

若如初见. 提交于 2019-11-26 12:09:27
问题 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

Postgres JSON data type Rails query

…衆ロ難τιáo~ 提交于 2019-11-26 08:46:56
问题 I am using Postgres\' json data type but want to do a query/ordering with data that is nested within the json. I want to order or query with .where on the json data type. For example, I want to query for users that have a follower count > 500 or I want to order by follower or following count. Thanks! Example: model User data: { \"photos\"=>[ {\"type\"=>\"facebook\", \"type_id\"=>\"facebook\", \"type_name\"=>\"Facebook\", \"url\"=>\"facebook.com\"} ], \"social_profiles\"=>[ {\"type\"=>\"vimeo\

Is there a shortcut for SELECT * FROM?

蹲街弑〆低调 提交于 2019-11-26 04:53:53
问题 There are many useful shortcuts in psql console like \\d or \\l . I wondering is there one for SELECT * FROM table_name ? I use this query often for learning purposes so it would be quite helpful not to have to write select * from ... all the time. 回答1: There is a "shortcut" for SELECT * FROM in standard SQL, so you can use it in psql: TABLE tablename; This syntax shorthand can only be used with a limited range of clauses. The manual: It can be used as a top-level command or as a space-saving