psql

Disable wrapping in Psql output

☆樱花仙子☆ 提交于 2019-12-03 14:38:13
问题 When using Psql in Linux, if the result of my SQL query contains many columns or long strings of data, it will wrap the initial view and only once I scroll to the side will it stop wrapping and show each row on a separate line. I've tried various \pset options such as format unaligned , format aligned , format wrapped , columns 0 , columns 1000 , but none seemed to fully stop wrapping unless I generate static output to a file. How can I set it to never wrap the output while still being

postgresql with jdbc and stored procedures (functions): ResultSet

送分小仙女□ 提交于 2019-12-03 09:00:41
I just tried to call a stored function from the server (getStat), that is looking like this: create type stat as (type text, location text, number int); create function getStat() returns setof stat as 'select distinct table1.type, table1.location, table1.number from table1, table2 where table2.finding=10 order by number desc;' language 'sql'; Now here is the jdbc code: CallableStatement callable = null; String storedProc = "{call getStat(?, ?, ?)}"; try { callable = connection.prepareCall(storedProc); callable.registerOutParameter(1, java.sql.Types.VARCHAR); callable.registerOutParameter(2,

Postgres COPY FROM csv file- No such file or directory

情到浓时终转凉″ 提交于 2019-12-03 08:37:31
问题 I'm trying to import a (rather large) .txt file into a table geonames in PostgreSQL 9.1. I'm in the /~ directory of my server, with a file named US.txt placed in that directory. I set the search_path variable to geochat, the name of the database I'm working in. I then enter this query: COPY geonames FROM 'US.txt', DELIMITER E'\t', NULL 'NULL'); I then receive this error: ERROR: could not open file "US.txt" for reading: No such file or directory. Do I have to type in \i US.txt or something

how to set up the psql command in cygwin?

对着背影说爱祢 提交于 2019-12-03 07:22:45
问题 I have a local dev site on my machine with Apache server and PostgreSQL 9.1 database. As I'm using Windows, I also installed Cygwin. I want to access to database and make some queries via Cygwin insead of pgAdmin III, but it tells me that psql command not found. How should I set up the psql command in cygwin? 回答1: As of today, you just have to install postgresql-client package in cygwin: Run your cygwin setup.exe file (this can be run multiple times to add more packages). Type postgresql into

PostgreSQL user listing

让人想犯罪 __ 提交于 2019-12-03 02:36:59
问题 I want to get a list of users for a certain database in psql - for example "template0". Who are the users? Or for "template1" database: - who are the users there? Already tried: \du+ -- no database is Listed not Users Select * from "pg_users"; -- no database is listed 回答1: User aren't actually, "for the database", they're for cluster and are given different permissions to access databases. To list users \du should do, but you need to be connected. Something like psql template1 -c '\du' from

How to select a schema in postgres when using psql?

家住魔仙堡 提交于 2019-12-03 01:45:06
问题 I have a postgres database with multiple schemas. When I connect to the database from a shell with psql and I run \dt it uses the default connection schema which is public . Is there a flag I can specify or how can I change the schema? 回答1: In PostgreSQL the system determines which table is meant by following a search path, which is a list of schemas to look in. The first matching table in the search path is taken to be the one wanted, otherwise, if there is no match a error is raised, even

psql: command not found Mac

寵の児 提交于 2019-12-03 01:28:34
问题 I installed PostgreSQL via the graphical install on http://www.postgresql.org/download/macosx/ I see it in my applications and also have the psql terminal in my applications. I need psql to work in the regular terminal for another bash script I'm running for an app. For some reason, when I run psql in the Mac terminal, my output is -bash: psql: command not found I ran the following in the terminal: locate psql | grep /bin and the output was /Library/PostgreSQL/9.5/bin/psql I then edited my ~/

customize pager in psql

。_饼干妹妹 提交于 2019-12-02 23:46:42
When I use psql , the command line tool of PostgreSQL, in interactive mode, it lists data as paginated output. However, because I use psql in a terminal application which can handle long outputs itself, I rather would like to get the whole output without the paginating with the annoying --more-- line. Is there any way to customise the paging behavior in psql ? I tried to set LESS in the surrounding shell environment to cat , but this din't help. Any suggestions? From the fine psql manual : \pset option [ value ] [...] pager Controls use of a pager program for query and psql help output. If the

Postgres COPY FROM csv file- No such file or directory

坚强是说给别人听的谎言 提交于 2019-12-02 22:27:59
I'm trying to import a (rather large) .txt file into a table geonames in PostgreSQL 9.1. I'm in the /~ directory of my server, with a file named US.txt placed in that directory. I set the search_path variable to geochat, the name of the database I'm working in. I then enter this query: COPY geonames FROM 'US.txt', DELIMITER E'\t', NULL 'NULL'); I then receive this error: ERROR: could not open file "US.txt" for reading: No such file or directory. Do I have to type in \i US.txt or something similar first, or should it just get it from the present working directory? Erwin Brandstetter A couple of

psql return code if zero rows found

霸气de小男生 提交于 2019-12-02 21:31:25
问题 I would like for my psql command to fail if zero rows are found: psql -U postgres -d db -c "select * from user where id=1 and name='Joe';" I want to be able to check the return value. Return 0 from the process(!) if at least one row exists and return non-zero from the psql process if no such row exists. How can I set a return code if no rows are found? 回答1: I don't think psql can do it by itself, but if you just want to see if there are any rows or not with the exit status you could combine