I have a View that has several fields.
When i INSERT INTO a view I run a function based on INSERT parametrs. The function returns a value.
How can I retrieve The value from rule?
INSERT RETURNING Gives me:
ERROR: cannot perform INSERT RETURNING on relation "full_subntes"
?????????: You need an unconditional ON INSERT DO INSTEAD rule with a…
I have a table with approx 5 million rows which has a fk constraint referencing the primary key of another table (also approx 5 million rows).
I need to delete about 75000 rows from both tables. I know that if I try doing this with the fk constraint enabled it's going to take an unacceptable amount of time.
Coming from an Oracle background…
It's a CentOS server (I don't know the specs) and just before anybody states the obvious, keep in mind these mitigating factors:
the server does a nightly VACUUM job
all the tables are indexed
it's pretty much read only (meaning the DBs are not increasing in size)
the number of queries being ran has been the same every month
Here's a…
I've always used either auto_generated or Sequences in the past for my primary keys. With the current system I'm working on there is the possibility of having to eventually partition the data which has never been a requirement in the past. Knowing that I may need to partition the data in the future, is there any advantage of using…
I'm trying to select a number of fields, one of which needs to be an array with each element of the array containing two values. Each array item needs to contain a name (character varying) and an ID (numeric). I know how to return an array of single values (using the ARRAY keyword) but I'm unsure of how to return an array of an…
I am running unicorn on Ubuntu 11, Rails 3.0, and Ruby 1.8.7.
It is an 8 core ec2 box, and I am running 15 workers. CPU never seems to get pinned, and I seem to be handling requests pretty nicely.
My question concerns memory usage, and what concerns I should have with what I am seeing. (if any)
Here is the scenario:
Under…
So I want to prepare a query something like:
SELECT id FROM users WHERE (branch, cid) IN $1;
But I then need to bind a variable length list of arrays like (('a','b'),('c','d')) to it. How do I go about doing this? I've tried using ANY but can't seem to get the syntax right.
Cheers,
Alec
Edit:
After some fiddling…
I have a large table ( 50m rows) which has some data with an ID and timestamp.
I need to query the table to select all rows with a certain ID where the timestamp is between two dates, but it currently takes over 2 minutes on a high end machine. I'd really like to speed it up.
I have found this tip which recommends…
I know this has probably been asked before, but I can't find it with SO's search.
Lets say i've TABLE1 and TABLE2, who should I expect the performance of a query such as this:
SELECT * FROM TABLE1 WHERE id IN SUBQUERY_ON_TABLE2;
as the number of rows in TABLE1 and TABLE2 grow and id is a primary key on TABLE1.
…
I keep getting an "Notice: Undefined index: did" error with this query, and I'm not understanding why... I'm much more used to mysql, so, maybe the syntax is wrong?
This is the php query code:
function get_demos() {
global $session;
$demo = array();
$result = pg_query("SELECT…
This is a multi-part question.
I have a table similar to this:
CREATE TABLE sales_data (
Company character(50),
Contract character(50),
top_revenue_sum integer,
top_revenue_sales integer,
last_sale timestamp) ;
I'd like to create a trigger for new inserts into this table, something like…
I need to update some timestamp columns in a table in a PostGres (8.3) database.
My query (simplified) look like this:
update table1 set dateA = dateA + interval '10 hours' where id = 1234;
This is part of a script and there's a lot to update so my preference is to use bind variables, rather than…
I am using pg_buffercache module for finding hogs eating up my RAM cache. For example when I run this query:
SELECT c.relname, count(*) AS buffers
FROM pg_buffercache b INNER JOIN pg_class c
ON b.relfilenode = c.relfilenode AND
b.reldatabase IN (0, (SELECT oid FROM pg_database WHERE…
Hello,
for some reason I'm experiencing the Operational Error with "can't rollback" message when I attempt to roll back my transaction in the following context:
try:
cursors[instance].execute("lock revision, app, timeout IN SHARE MODE")
cursors[instance].execute("insert into app…
Table output_values_center1 (and some other) inherits output_values. Periodically I truncate table output_values_center1 and load new data (in one transaction). In that time user can request some data and he got error message. Why it ever happens (select query requests only one record)…
CREATE FUNCTION foo() RETURNS text
LANGUAGE plperl
AS $$
return 'foo';
$$;
CREATE FUNCTION foobar() RETURNS text
LANGUAGE plperl
AS $$
return foo() . 'bar';
$$;
I'm trying to compose results using multiple functions, but when i call foobar() i get an…
I have some django code that runs fine on a SQLite database or on a MySQL database, but it runs into problems with Postgres, and it's making me crazy that no one has has this issue before. I think it may also be related to the way querysets are evaluated by the pager.
In a view I…
I'm trying to insert data into a table from a template table. I need to rewrite one of the columns for which I wanted to use a directly indexed array expression, but I can't seem to find how to do this, if it is even possible. The scenario:
create table template (
id integer,
…
Hi
I have two tables, Products and BundleProducts that have o2o relation with BaseProducts.
A BundleProduct is a collection of Products using a m2m realtion to the Products table.
Products has a price column and the price of a BundleProduct is calculated as the sum of the prices…
Hello,
please help me with 1 more PL/pgSQL question.
I have a PHP-script run as daily cronjob and deleting old records from 1 main table and few further tables referencing its "id" column:
create or replace function quincytrack_clean()
returns integer as $BODY$
…
I am trying to execute following query through PgAdmin utility.
CREATE TABLE svcr."EventLogs" ("eventId" BIGINT NOT NULL,
"eventTime" TIMESTAMP WITH TIME ZONE NOT NULL, "userid" CITEXT,
"realmid" CITEXT NOT NULL, "onUserid" CITEXT, "description" TEXT,
CONSTRAINT…
I have worked out how to calculate the correlation coefficient between two fields if both are in the same table:
SELECT corr(column1, column2) FROM table WHERE <my filters>;
...but I can't work out how to do it when the columns are from different tables (I…