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
41
votes
8 answers

Default password for my user in postgresql

I installed postgresql on my Mac through homebrew. It said it didn't create a postgres account, but is using an account with my username instead. However, running the command psql fails because when I type in my password, it says it's wrong. I've…
Hugo
  • 2,186
  • 8
  • 28
  • 44
41
votes
2 answers

Postgres - CREATE TABLE FROM SELECT

I have two tables, one contains a large list of IDs and Info regarding those ids. I have a second table Graph which just has two columns, each column contains the aforementioned id numbers, multiple times. I want to trim the size of my Info table by…
user2923767
  • 567
  • 1
  • 4
  • 13
41
votes
3 answers

Postgres: left join with order by and limit 1

I have the situation: Table1 has a list of companies. Table2 has a list of addresses. Table3 is a N relationship of Table1 and Table2, with fields 'begin' and 'end'. Because companies may move over time, a LEFT JOIN among them results in multiple…
41
votes
6 answers

PSQLException: ERROR: relation "TABLE_NAME" does not exist

I am trying to run hibernate on a PostgreSQL 8.4.2 DB. Whenever I try to run a simple java code like: List users = service.findAllUsers(); I get the following error: PSQLException: ERROR: relation "TABLE_NAME" does not exist Since I have…
Lucas T
  • 3,011
  • 6
  • 29
  • 36
41
votes
4 answers

syntax error at or near "-" in PostgreSQL

I'm trying to run a query to update the user password using. alter user dell-sys with password 'Pass@133'; But because of - it's giving me error like, ERROR: syntax error at or near "-" LINE 1: alter user dell-sys with password 'Pass@133'; …
OpenCurious
  • 2,916
  • 5
  • 22
  • 25
41
votes
9 answers

Character with encoding UTF8 has no equivalent in WIN1252

I am getting the following exception: Caused by: org.postgresql.util.PSQLException: ERROR: character 0xefbfbd of encoding "UTF8" has no equivalent in "WIN1252" Is there a way to eradicate such characters, either via SQL or programmatically? (SQL…
Monis Iqbal
  • 1,987
  • 7
  • 26
  • 42
41
votes
2 answers

PostgreSQL cannot begin/end transactions in PL/pgSQL

I am seeking clarification of how to ensure an atomic transaction in a plpgsql function, and where the isolation level is set for this particular change to the database. In the plpgsql function shown below, I want to make sure that BOTH the deletion…
Tim
  • 8,669
  • 31
  • 105
  • 183
41
votes
5 answers

PostgreSQL convert columns to rows? Transpose?

I have a PostgreSQL function (or table) which gives me the following output: Sl.no username Designation salary etc.. 1 A XYZ 10000 ... 2 B RTS 50000 ... 3 C …
DonRaHulk
  • 575
  • 1
  • 6
  • 18
41
votes
6 answers

How to create sequence if not exists

I tried to use code from Check if sequence exists in Postgres (plpgsql). To create sequence if it does not exists. Running this code two times causes an exception: sequence ... already exists. How to create sequence only if it does not exist? If…
Andrus
  • 26,339
  • 60
  • 204
  • 378
41
votes
7 answers

Add element to JSON object in Postgres

I have a text field in a database (postgres 9.2.1) with a json blob in it. It looks something similar to this except all on a single line, obviously: { "keyword": { "checked": "1", "label": "Keyword" }, "agency_name": { "checked":…
PREEB
  • 1,320
  • 2
  • 14
  • 27
41
votes
5 answers

dynamic sql query in postgres

I was attempting to use Dynamic SQL to run some queries in postgres. Example: EXECUTE format('SELECT * from result_%s_table', quote_ident((select id from ids where condition = some_condition))) I have to query a table, which is of the form…
psteelk
  • 1,305
  • 3
  • 16
  • 24
41
votes
4 answers

Conversion String to UUID in Postgres and Java

I need to convert String ( text ) to UUID ( Postgres ) and keep the same sorting like for a String. Is it possible? I saw the UUID base on the time, so maybe it's not possible?
javalonde
  • 549
  • 2
  • 6
  • 7
41
votes
2 answers

date_trunc 5 minute interval in PostgreSQL

Possible Duplicate: What is the fastest way to truncate timestamps to 5 minutes in Postgres? Postgresql SQL GROUP BY time interval with arbitrary accuracy (down to milli seconds) I want to aggregate data at 5 minute intervals in PostgreSQL. If I…
prateekk
  • 411
  • 1
  • 4
  • 3
41
votes
2 answers

Regular expression find and replace in Postgres

I have a table that contains a number of rows with columns containing a URL. The URL is of the form: http://one.example1.com:9999/dotFile.com I would like to replace all matches in that column with http://example2.com/dotFile.com while retaining…
ringocub
  • 427
  • 1
  • 4
  • 7
41
votes
4 answers

Postgres won't accept table alias before column name

I'm using a framework (Jodd) which is adding the table alias to the column names in a SQL Select. It looks like well-formed SQL, but Postgres chokes on it. update GREETING Greeting set Greeting.ID=5, Greeting.NAME='World', …
Ron Romero
  • 9,211
  • 8
  • 43
  • 64
1 2 3
99
100