psql

How do I change the max column width in PostgreSQL?

為{幸葍}努か 提交于 2021-02-19 02:36:05
问题 I have simple SQL query that selects a few rows from one table. One of the columns contains very long strings. I would like to set a maximum column width so that it is easier to read. I don't have access to environment variables through \pset. 来源: https://stackoverflow.com/questions/48481809/how-do-i-change-the-max-column-width-in-postgresql

What causes “More is not recognized…” error when running Postgresql 11 on a Windows machine?

断了今生、忘了曾经 提交于 2021-02-13 17:39:34
问题 I keep getting this error: more is not a recognized internal or external command. when I run this command, SELECT * FROM users; I am new to Postgres. I had to set my path multiple times to: C:\Program Files\PostgreSQL\11\bins 回答1: Assuming you are using psql . When the result of query exceeds the size of the console window, psql tries to use a pager to provide some basic scrolling facility in the result. By default this is the command more . Although I find it hard to believe that your system

psql import .csv - Double Quoted fields and Single Double Quote Values

≡放荡痞女 提交于 2021-02-11 17:39:37
问题 Hello Stack Overflowers, Weird question. I am having trouble importing a .csv file using psql command line arguments... The .csv is comma delimited and there are double quotes around cells/fields that have commas in them. I run into an issue where one of the cells/fields has a single double-quote that is being used for inches. So in the example below, it thinks the bottom two rows are all one cell/field. I can't seem to find a way to make this import correctly. I am hoping to not have to make

Creating a PostgreSQL database backup via psql on macOS

白昼怎懂夜的黑 提交于 2021-02-11 16:00:36
问题 I'm trying to create a PostgreSQL local db dump via Terminal on macOS using psql . My next step is to upload/import my entire db to my Amazon RDS PostgreSQL db instance. Can anyone help me with the Terminal command to create a dump file 'mydbdump.sql' for my 'mydb' database. I've sorted through existing questions, searched forums (tried similar Stack Overflow question), even Amazon RDS docs (above, link), and am having no luck with the commands from any of these docs. What am I doing wrong?

Making an empty output from psql

情到浓时终转凉″ 提交于 2021-02-09 11:55:29
问题 I am running a psql command that executes a complex query. There's nothing that query produces, as such, psql returns "(No rows)" in the output. Is there a way to make psql to return an empty string? I've tried using --pset=tuples-only=on and --pset=footer=off and -q in all variations, and it doesn't seem to work. Footer option works while in psql shell prompt, but doesn't work from script. Tried on 9.1.7, need this for 8.4, 9.1 and 9.2. 回答1: May be good enough: $ psql -Axt -c 'select 1 where

Making an empty output from psql

有些话、适合烂在心里 提交于 2021-02-09 11:55:14
问题 I am running a psql command that executes a complex query. There's nothing that query produces, as such, psql returns "(No rows)" in the output. Is there a way to make psql to return an empty string? I've tried using --pset=tuples-only=on and --pset=footer=off and -q in all variations, and it doesn't seem to work. Footer option works while in psql shell prompt, but doesn't work from script. Tried on 9.1.7, need this for 8.4, 9.1 and 9.2. 回答1: May be good enough: $ psql -Axt -c 'select 1 where

how to pass variable to copy command in Postgresql

心不动则不痛 提交于 2021-02-08 15:16:38
问题 I tried to make a variable in SQL statement in Postgresql, but it did not work. There are many csv files stored under the path. I want to set path in Postgresql that can tell copy command where can find csv files. SQL statement sample: \set outpath '/home/clients/ats-dev/' \COPY licenses (_id, name,number_seats ) FROM :outpath + 'licenses.csv' CSV HEADER DELIMITER ','; \COPY uploaded_files (_id, added_date ) FROM :outpath + 'files.csv' CSV HEADER DELIMITER ','; It did not work. I got error:

How can I quote a named argument passed in to psql?

牧云@^-^@ 提交于 2021-02-07 13:54:19
问题 psql has a construct for passing named arguments: psql -v name='value' which can then be referenced inside a script: SELECT :name; which will give the result ?column? ---------- value (1 row) During development, I need to drop and recreate copies of the database fairly frequently, so I'm trying to automate the process. So I need to run a query that forcibly disconnects all users and then drops the database. But the database this operates on will vary, so the database name needs to be an

How to set default display mode in psql

巧了我就是萌 提交于 2021-02-06 06:54:26
问题 Almost every psql query comes out an illegible mess if not preceded by display configuration commands such as \x auto . Typing this manually for each psql instance is annoying. Expanded display is used automatically. Is there any way to configure a better default display? Or perhaps the answer is to use a more advanced interactive terminal? 回答1: Use .psqlrc to set defaults. For the specific case of \x , newer psql versions (9.3, I think, but it might just be the 9.4 pre-release) can

“x is a procedure, use ”call“” when I am already using call

拈花ヽ惹草 提交于 2021-02-05 07:09:49
问题 I'm using Postgres 12 and have written this procedure: CREATE OR REPLACE PROCEDURE reduceStock(id INTEGER, soldQuantity INTEGER) LANGUAGE plpgsql AS $$ BEGIN UPDATE inventory SET ProductStockAmount = ProductStockAmount - soldQuantity WHERE ProductID = id; END; $$; It works perfectly if I open up psql on the command line and run call reduceStock(1,1); However, calling it from my Java program as follows: CallableStatement stmt = conn.prepareCall("{call reduceStock(?, ?)}"); stmt.setInt(1,