Questions tagged [postgresql]

PostgreSQL is an open-source, relational database management system (RDBMS) available for all major platforms, including Linux, UNIX, Windows and OS X. Mention your version of Postgres when asking questions. Consider dba.stackexchange.com for questions concerning the administration or advanced features.

PostgreSQL (often "Postgres", never "Postgre"), is an object-relational database management system (ORDBMS) available for all major operating systems. It is free and open-source software released under the PostgreSQL License, an MIT-style license. PostgreSQL is developed by the PostgreSQL Global Development Group, consisting of volunteers employed by companies such as Red Hat and EnterpriseDB.

PostgreSQL is pronounced as "post-grez-q-l". Postgres is pronounced as "post-grez".

Numerous forks of Postgres exist for specialized tasks, such as Greenplum Database, Amazon Redshift, ParAccel, Postgres-XC, Postgres-XL, PPAS, etc. Their features and syntax differ from stock PostgreSQL. Declare what you are using and add a tag.

PostgreSQL Features

How to ask good questions

For performance questions consider instructions for .

For questions targeting a specific version add a version tag: , etc.

Questions concerning the administration or advanced features are best directed to dba.StackExchange.com.

The Guide to Reporting Problems on the PostgreSQL wiki is helpful reading.

  • Show at least your major PostgreSQL version from SELECT version().

  • Include the full text of relevant error messages, SQL queries, etc.

  • Where appropriate, supply a test case with CREATE TABLE and INSERT statements with sample data and expected results. A fiddle site like dbfiddle.uk or sqlfiddle.com is typically useful.

  • If you've asked previous, related questions, add a link.

  • If you re-post a mailing list question, link to the page in the mailing list archives. And vice versa.

  • Know about PostgreSQL current settings/backend config with:

     SELECT name, current_setting(name), source FROM pg_settings
     WHERE  source NOT IN ('default', 'override');
    

Resources

Useful links

171962 questions
40
votes
2 answers

Selecting records between two timestamps

I am converting an Unix script with a SQL transact command to a PostgreSQL command. I have a table with records that have a field last_update_time(xtime) and I want to select every record in the table that has been updated within a selected period.…
Sharon
  • 401
  • 1
  • 4
  • 5
40
votes
2 answers

Use binary COPY table FROM with psycopg2

I have tens of millions of rows to transfer from multidimensional array files into a PostgreSQL database. My tools are Python and psycopg2. The most efficient way to bulk instert data is using copy_from. However, my data are mostly 32-bit floating…
Mike T
  • 41,085
  • 18
  • 152
  • 203
40
votes
8 answers

How to download Postgres bytea column as file

Currently, i have a number of files stored in postgres 8.4 as bytea. The file types are .doc, .odt, .pdf, .txt and etc. May i know how to download all the file stored in Postgres because i need to to do a backup. I need them in their original file…
Chong Hsiung
  • 401
  • 1
  • 4
  • 3
40
votes
4 answers

how to fix "OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly"

Services My service based on flask + postgresql + gunicorn + supervisor + nginx When deploying by docker, after running the service, then accessing the api, sometimes it told the error message, and sometimes it workes well. And the sqlachemy connect…
junxian diao
  • 573
  • 1
  • 6
  • 15
40
votes
1 answer

How do I solve «panic: sql: unknown driver "postgres" (forgotten import?)»?

I'm trying to INSERT data into POSTGRES from a .csv (pre-fixed width / tabular ) with GO. What I've done: package main import ( "bufio" "database/sql" "encoding/csv" "encoding/json" "fmt" "io" "log" "os" ) type…
gasp
  • 401
  • 1
  • 4
  • 3
40
votes
4 answers

When I run test cases I get this error: psycopg2.OperationalError: cursor "_django_curs_140351416325888_23" does not exist

I'm trying to run test cases, but I get below error. Run command : python manage.py test Type 'yes' if you would like to try deleting the test database 'test_project_management_db', or 'no' to cancel: yes Destroying old test database for alias…
Ankit Kumar Rathod
  • 503
  • 1
  • 4
  • 7
40
votes
3 answers

how to convert integer minutes to interval in postgres

I'm trying to convert minutes which are in integer to interval in postgres Is there any function that will help me to convert it to interval or should i have divide it by 60 and get the final result 20 minutes will be like 00:20:00 as result
Abhijeet Gulve
  • 799
  • 1
  • 9
  • 23
40
votes
7 answers

Copy a postgres database without LOCK permissions

I need to copy a postgres DB from one server to another, but the credentials I have do not have permission to lock the database so a pg_dump fails. I have full read/update/insert rights to the DB in question. How can I make a copy of this database?…
DrStalker
  • 9,061
  • 17
  • 43
  • 47
40
votes
1 answer

What is a Postgres "session"?

What is a Postgres "session" in the context of session-level advisory locks? Can two threads/processes share the same session?
Barry Fruitman
  • 12,316
  • 13
  • 72
  • 135
40
votes
9 answers

SQL: Advantages of an ENUM vs. a one-to-many relationship?

I very rarely see ENUM datatypes used in the wild; a developer almost always just uses a secondary table that looks like this: CREATE TABLE officer_ranks ( id int PRIMARY KEY ,title varchar NOT NULL UNIQUE); INSERT INTO officer_ranks VALUES…
jamieb
  • 9,847
  • 14
  • 48
  • 63
40
votes
4 answers

Adding value to Postgres integer array

I am looking for help in adding a value 10 to an int[] in PostgreSQL 9.5. Looking at the documentation I should be able to use this format to update it but it is not working: int[] + int push element onto array (add it to end of array) I have…
Kyle K
  • 503
  • 1
  • 4
  • 9
40
votes
4 answers

Extract key, value from json objects in Postgres

I have a Postgres table that has content similar to this: id | data 1 | {"a":"4", "b":"5"} 2 | {"a":"6", "b":"7"} 3 | {"a":"8", "b":"9"} The first column is an integer and the second is a json column. I want to be able to expand out the…
Tom G
  • 2,025
  • 3
  • 21
  • 32
40
votes
2 answers

Postgresql escape single quote in where clause

so I am trying to run a script like this one: select id from owner where owner.name = "john's" and I am getting this error: ERROR: column "john's" does not exist. Also I tried like this: where owner.name = 'john\'s', but it dit not work Anyone…
Eugen
  • 463
  • 1
  • 4
  • 5
40
votes
6 answers

Postgresql gem install pg 0.18.4 passes, bundle install fails

Mac OS El Capitan Bundle install fails with: compiling pg_connection.c pg_connection.c:2394:3: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration] gettimeofday(&currtime,…
jasonm
  • 1,020
  • 2
  • 11
  • 24
40
votes
3 answers

How to get a real time within PostgreSQL transaction?

As far as I understand now() returns the same time during the whole PostgreSQL transaction? But how to get real time? Also, I am interested if there any configuration parameter to limit duration of transaction, so that after this period expiration…
seas
  • 1,482
  • 2
  • 18
  • 29
1 2 3
99
100