Questions tagged [psql]

Primary interactive shell for PostgreSQL. NOT a synonym for PostgreSQL.

psql is a terminal-based client to PostgreSQL, that's packaged with the software. It lets you edit queries interactively, issue them to PostgreSQL, and see the results. You can read and write to / from files and use it for scripting.

Additionally, psql provides a set of meta-commands and other shell-like features to facilitate writing scripts and automating a wide range of tasks.

Questions with this tag should probably be tagged , too.
But only questions dealing with the command-line interface should be tagged .


Questions referring to the procedural language "psql" for the Firebird database should be tagged with

3588 questions
1
vote
1 answer

Is it possible to import OSM data from inside psql?

I am working on this Bash Script for Dockerfile: #!/bin/bash set -e gosu postgres postgres --single -jE <<-EOL CREATE USER "$OSM_USER"; EOL gosu postgres postgres --single -jE <<-EOL CREATE DATABASE "$OSM_DB"; EOL gosu postgres postgres…
Andrew Ramnikov
  • 783
  • 2
  • 9
  • 30
1
vote
1 answer

Postgresql copy fails on pretty printed JSON

I have a file with JSON data in it. The file was given to me "pretty printed" (with indents, etc), but the PostgreSQL \copy fails to load it. It gives the following error: CONTEXT: JSON data, line 1: { COPY test_data, line 1, column data: "{" This…
David S
  • 12,967
  • 12
  • 55
  • 93
1
vote
1 answer

Insert into table after pg dump

I used pg_dump to populate a table in new database. After that, I want to be able to insert rows into table using the default autoincrementer of the serial key. Here is what I have in table: In this table (smtable), a is the key (set as…
faizanjehangir
  • 2,771
  • 6
  • 45
  • 83
1
vote
2 answers

Why does psql not recognise my single quotes?

$ psql -E --host=xxx --port=yyy --username=chi --dbname=C_DB -c 'DELETE FROM "Stock_Profile" WHERE "Symbol" = 'MSFT'; ' ERROR: column "msft" does not exist LINE 1: DELETE FROM "Stock_Profile" WHERE "Symbol" = MSFT; How do I show psql that MSFT is…
ManInMoon
  • 6,795
  • 15
  • 70
  • 133
1
vote
1 answer

Create a build file git push gitlab ci

I am working on a plsql project (with a lot of stored procedure(SP)) hosted on my gitlab server, every SP is on a single file. I want create a new file on every build (using gitlab-ci) that contains the changes of the SP. My question is how can I…
emperator
  • 23
  • 1
  • 5
1
vote
1 answer

Left join pre-filtering on first table in postgres

I want to run a query to get user photo album ids, names, and picture count in the album. This query works: SELECT album.id, album.name, count(pictures.*) FROM album LEFT JOIN pictures ON (pictures.album_id=album.id) WHERE album.owner = ? GROUP…
Charles L.
  • 5,795
  • 10
  • 40
  • 60
1
vote
1 answer

Rails 4 App : How to set up the same application along with PSQL Database in New System?

I am working with a Rails 4 app, I am using PSQL both in my development and production. Due to some reason I have to work with a new computer/laptop so I set up Rails environment in it and cloned my app into it, but what I really require is that, I…
Praveen George
  • 9,237
  • 4
  • 26
  • 53
1
vote
1 answer

Postgresql psql command dumping error

im trying to export my table from Postgresql (RDS) on Amazon Web Services using the following command: psql -t -A -F"," -c "select * from Album" > album.csv -h amazon-instance -p 5432 -U username -W -d chinook I get this error message: ERROR: …
user1896576
  • 75
  • 1
  • 9
1
vote
1 answer

Postgres: how to disconnect without logging out?

Using psql, how can I disconnect from an established connection without logging out? To be more specific: Assuming the database server runs on localhost, I connect to the db server using psql -U after that I am in the PSQL console. From…
Ueli Hofstetter
  • 2,409
  • 4
  • 29
  • 52
1
vote
2 answers

average per row based on a boolean value count in postgres

Is it possible to find the average of multiple rows in a column grouped by some criteria, but the average is not a numerics value, actually it another count under a specific boolean condition: select count(commit) from table_x where contains_bug =…
ALS_WV
  • 91
  • 6
1
vote
1 answer

Python string substitution for dynamic column name and values

I have following query to retrieve data from PostgreSQL. select_stmt = "SELECT * FROM kart_user WHERE token = %(token)s" cursor.execute(select_stmt, { 'token': 2 }) Some case dictionary may contain multiple keys and values Eg- { 'token':…
Abdul Razak
  • 2,654
  • 2
  • 18
  • 24
1
vote
1 answer

psql syntax error at command line with variable interpolation

I have a scenario like below with Postgres 9.4.5: CREATE OR REPLACE FUNCTION something(varA text) RETURNS void AS $$ BEGIN ... RAISE INFO '%',varA; END; $$ LANGUAGE plpgsql; DO $$ declare varA text := :cmd_line_arg; begin perform…
Koushik Shetty
  • 2,146
  • 4
  • 20
  • 31
1
vote
1 answer

psql 9.1 merge select result in one row

I have 4 tables and each have over 10K row: Table "public.items" Column | Type | Modifiers ----------------+------------------+--------------- id | integer …
mamesaye
  • 2,033
  • 2
  • 32
  • 49
1
vote
1 answer

Postgresql transfer table data from different databases

I have two apps, with same tables. One of app collecting data from web. I want to send the datas to my second(web app)'s app database. With the code below, I have created the file with datas: pg_dump -U username -t public."table_name" -d database…
Samican
  • 11
  • 3
1
vote
0 answers

UPDATE with SQL Cursor

I need help with my sql script. Inventory is a table which contains orderunit, location, siteid and itemnum. This update aims to change all "orderunit = NULL" by the same item (itemnum) in such a way : %_TAB => %_TD and %_TD => %_ACM I want the…
robinwood13
  • 179
  • 1
  • 1
  • 8