0

I am trying to consult a database using pgAdmin3 and I need to join to tables. I am using the following code:

SELECT table1.species, table1.trait, table1.value, table1.units, table2.id, table2.family, table2.latitude, table2.longitude, table2.species as speciescheck
  FROM table1 INNER JOIN table2
    ON table1.species = table2.species

But I keep running this error:

an out of memory error

So I've tried to insert my result in a new table, as follow:

CREATE TABLE new_table AS
SELECT table1.species, table1.trait, table1.value, table1.units, table2.id, table2.family, table2.latitude, table2.longitude, table2.species as speciescheck
  FROM table1 INNER JOIN table2
    ON table1.species = table2.species

And still got an error:

ERROR: could not extend file "base/17675/43101.15": No space left on device
SQL state: 53100
Hint: Check free disk space.

I am very very new at this (is the first time I have to deal with PostgreSQL) and I guess I can do something to optimize this query and avoid this type of error. I have no privileges in the database. Can anyone help?? Thanks in advance!

Updated: Table 1 description

-- Table: table1

-- DROP TABLE table1;

CREATE TABLE table1
(
  species character varying(100),
  trait character varying(50),
  value double precision,
  units character varying(50)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE table1
  OWNER TO postgres;
GRANT ALL ON TABLE table1 TO postgres;
GRANT SELECT ON TABLE table1 TO banco;

-- Index: speciestable1_idx

-- DROP INDEX speciestable1_idx;

CREATE INDEX speciestable1_idx
  ON table1 
  USING btree
  (species COLLATE pg_catalog."default");

-- Index: traittype_idx

-- DROP INDEX traittype_idx;

CREATE INDEX traittype_idx
  ON table1
  USING btree
  (trait COLLATE pg_catalog."default");

and table2 as:

-- Table: table2 

-- DROP TABLE table2;

CREATE TABLE table2
(
  id integer NOT NULL,
  family character varying(40),
  species character varying(100),
  plotarea real,
  latitude double precision,
  longitude double precision,
  source integer,
  latlon geometry,
  CONSTRAINT table2_pkey PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE table2
  OWNER TO postgres;
GRANT ALL ON TABLE table2 TO postgres;
GRANT SELECT ON TABLE table2 TO banco;

-- Index: latlon_gist

-- DROP INDEX latlon_gist;

CREATE INDEX latlon_gist
  ON table2 
  USING gist
  (latlon);

-- Index: species_idx

-- DROP INDEX species_idx;

CREATE INDEX species_idx
  ON table2
  USING btree
  (species COLLATE pg_catalog."default");
1
  • this question is unanswerable without the table definitions. What is species ? is it at least a natural key on one of the two tables? Commented Jun 11, 2016 at 23:58

1 Answer 1

1

You're performing a join between two tables on the column species. Not sure what's in your data, but if species is a column with significantly fewer values than the number of records (e.g. if species is "elephant", "giraffe" and you're analyzing all animals in Africa), this join will match every elephant with every elephant.

When joining two tables most of the time you try to use a unique or close to unique attribute, like id (not sure what id means in your case, but could be it).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.