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
0 answers

How to query sum of 2 columns from a child table and group by according to a column in parent table?

I have two tables (foo and bar, each having more than 40000 rows), with one referencing another, with many-to-one, joinedload relationship, I want to get an aggregate sum (based on uid in foo, i.e. many rows in foo table can have same u_id) of two…
DarthSpeedious
  • 965
  • 1
  • 13
  • 25
1
vote
0 answers

ERROR: could not open file - No such file or directory [PHP, PDO]

I'm trying to open a file and IMPORT it to PSQL $sql ="COPY r_vehicle_submodel FROM '".$filePath."' DELIMITER ',' CSV"; However it display me error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[58P01]: Undefined file: 7…
Andurit
  • 5,612
  • 14
  • 69
  • 121
1
vote
1 answer

Unable to create new Postgres database

I'm unable to create a new database for the first time after installing postgres.app on my macbook pro Anyone here can point me to the origin of the problem ?
mounaim
  • 1,132
  • 7
  • 29
  • 56
1
vote
1 answer

rails joining two tables using three params

First things first i'm using Psql, If that helps, Probably doesnt matter. I have two tables, (they have the model has_many inbetween) # models RegUser(id, Email, Name) Booking(id , Event_id, Reg_user_id) How do i go about linking these two together…
Tester123
  • 219
  • 2
  • 15
1
vote
2 answers

How to use COUNT to calculate number of occurence in two columns?

I am having two tables. Table 1: Consists of name of the players and their id's. tournament=> select * from Players; id | name ----+-------- 1 | Rahul 2 | Rohit 3 | Ramesh 4 | Roshan 5 | Ryan 6 | Romelu 7 | Roman 8 | Rampu (8…
Rahul Shrivastava
  • 1,391
  • 3
  • 14
  • 38
1
vote
1 answer

Directing error output from Bash psql

I'm using psql to connect to a Redshift database. Redshift doesn't seem to support \set ON_ERROR_STOP TRUE so I can't use that to stop the query and direct something to error output. Is there another way to catch any error from a psql connection or…
simplycoding
  • 2,770
  • 9
  • 46
  • 91
1
vote
0 answers

Error in PostgreSQL : Acting strange after inserting wrong query

I'm trying to create a table in PostgreSQL, but it returns an error. This is my statement: CREATE TABLE sportschema.zaal( zaalnr serial PRIMARY KEY, naam varchar(50), adres varchar(50), telefoonnummer varchar(50) ); If I execute…
Melvin
  • 77
  • 1
  • 10
1
vote
4 answers

Insert values of one table in a database to another table in another database

I would like to take some data from a table from DB1 and insert some of that data to a table in DB2. How would one proceed to do this? This is what I've got so far: CREATE VIEW old_study AS SELECT * FROM dblink('dbname=mydb', 'select…
Michael Bui
  • 190
  • 2
  • 12
1
vote
1 answer

Get date from timestamp without time zone

The query below returns a table with data type time stamp without time zone. How do I format this query so it removes the timestamp and just save the date? SELECT * FROM dblink('dbname=mydb', 'select startdate from study') as t1(start timestamp…
Michael Bui
  • 190
  • 2
  • 12
1
vote
2 answers

How does rails assign a foreign_key automatically when I push a created model into it?

I've been dabbling around in rails and I'm having a hard time understanding how a foreign key automatically get's populated in a table of a model when I push something into it. For example, in a 1:N table relationship of Cart to Ingredients(assuming…
Justin Reyes
  • 153
  • 1
  • 1
  • 11
1
vote
1 answer

PostgreSQL 8.3.11 locked; orphaned pg_toast database object recovery

Howdy Slack Overflowvians. So I came across this PostgreSQL server running 8.3.11 (yeah I know), that was in a locked state with: ERROR: database is not accepting commands to avoid wraparound data loss in database "postgres" HINT: Stop the…
1
vote
2 answers

Postgresql:exporting data from local database to remote server in csv

I want to send data from my local postgresql to a remote server in csv form.. something similar to copy (select * from table) to /home/ubuntu/a.csv with csv But in place of local direcory, I want to take this csv dump in other server
Deepak Banka
  • 591
  • 1
  • 6
  • 24
1
vote
0 answers

PSQL how to do math between JSONB fields?

So I have table with "data" type JSONB column. I want do some calculations add/sub between values in the row. How I can do that? psql> select 2 + ("data"->'field') - ("data"->'anotherField') from js_data_table; This one produces an syntax…
M_F
  • 406
  • 7
  • 16
1
vote
0 answers

Postgres search ASCII against UTF8

I created my database like this: CREATE DATABASE MYDATABASE WITH ENCODING 'UTF8' LC_COLLATE='ro_RO.utf8' TEMPLATE template0; And I have a table county populated with UTF8 county names This query returns the result as I expect: SELECT * from county…
Mihai Zamfir
  • 2,167
  • 4
  • 22
  • 37
1
vote
1 answer

Postgres JSONB: query values in JSON array

Postgres 9.4 I have a record with a JSONB value like this: { "attributeA": 1, "attributeB": "Foo", "arrayAttribute": [ {"attributeC": 95, "attributeD": 5}, {"attributeC": 105, "attributeD": 5} ] } I want to write a query which…
Ben Smith
  • 851
  • 2
  • 10
  • 22
1 2 3
99
100