Tagged Questions
1
vote
1answer
47 views
How to make it impossible for a postgres user to delete databases?
What yould be the sql statement (that the user postgres will execute) so it will be impossible for the postgres user user1 to delete (drop) databases?
Or can I add a rule into some config file?
4
votes
2answers
92 views
PostgreSQL multi-column unique constraint and NULL values
I have a table like the following:
create table my_table (
id int8 not null,
id_A int8 not null,
id_B int8 not null,
id_C int8 null,
constraint pk_my_table primary key (id),
constraint ...
7
votes
1answer
108 views
Generate an exception with a Context
When PostgreSQL throws an exception, there is a line "CONTEXT" like:
ERROR: INSERT has more target COLUMNS than expressions
LINE 3: ...
...
3
votes
3answers
227 views
How can I insert if key not exist with PostgreSQL?
I have a table:
CREATE TABLE mytable (id SERIAL, name VARCHAR(10) PRIMARY KEY)
Now I want to add names to this table, but only if they not exist in the table already, and in both cases return the ...
1
vote
2answers
96 views
Reference a non primary key in another table in postgresql
I have a two columns should references two columns in another table. And those two columns are not primary key. I think I can't use foreign key, because it can only references primary keys.
3
votes
1answer
148 views
Is DB2 more reliable and stable compared to PostgreSQL or MySQL?
Always i was using MySQL or PostgreSQL for my projects such as Web/Desktop apps.
I had data loss few times and thanks to old backup i was always up and running.
But for a recent project for Airport, ...
8
votes
3answers
305 views
Should I use SQL JOIN or IN Clause?
I have a question about best approach. I am not sure which approach is best when data is considered variable in size.
Consider the following 3 TABLES:
EMPLOYEE
EMPLOYEE_ID, EMP_NAME
PROJECT
...
2
votes
2answers
433 views
How can I use a default value in a Select query in PostgreSQL?
I would like to use a default value for a column that should be used if no rows is returned. Is that possible in PostgreSQL? How can I do it? Or is there any other way I can solve this?
E.g. ...
3
votes
2answers
110 views
How can I specify the position for a new column in PostgreSQL?
If I have a table with the columns:
id | name | created_date
and would like to add a column, I use:
alter table my_table add column email varchar(255)
Then the column is added after the ...
1
vote
2answers
104 views
Understanding time format of the EXPLAIN command - Postgres
When I run the EXPLAIN ANALYZE command on a given query, I'm having a difficult time interpreting the outputted time value. For example (actual time=8163.890..8163.893). Do the internal decimals ...
4
votes
2answers
110 views
What is the consensus on using NOT NULL constraints on all text-based fields in a table?
Some of the tables I have come across don't have any NOT NULL constraints, which has yielded to some gotchas when querying.
I'm curious what the feelings are with using something like NOT NULL ...
4
votes
2answers
179 views
Estimate average and median efficiently in Postgres?
I have a Postgres database with tables in the billion scale. So any aggregate functions such as count() and avg(), as well as "order by random()" are very time consuming. Postgres has pg_catalog which ...
3
votes
2answers
108 views
ts_rank massively slows my query, how can I improve performance?
Here's the table definition
Table "public.kb_article_contents"
Column | Type | Modifiers
------------+----------+-----------
article_id | smallint | not null
contents | text | not ...
0
votes
0answers
157 views
[Pgpool-II] PITR online-recovery
I'm using pgpool-II + PostgreSQL 8.4 on three servers: primary + standby1 + standby2.
Replication mode is "on"
Load balance mode is "on" (between primary and standby1)
I followed the official ...
2
votes
2answers
846 views
How do I use currval() in PostgreSQL to get the last inserted id?
I have a table:
CREATE TABLE names (id serial, name varchar(20))
I want the "last inserted id" from that table, without using RETURNING id on insert. There seem to be a function CURRVAL(), but I ...