473,480 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

relation vs table...

I don't know what Postgres considers a relation and had no intention of
creating one when piping my schema to it... I always DROP TABLE before
CREATE TABLE, so here are the ERRORS emitted when building the database:

3:ERROR: table "country" does not exist
6:ERROR: table "customer" does not exist
11:ERROR: table "product" does not exist
15:ERROR: table "license" does not exist
19:ERROR: table "enduser" does not exist
24:ERROR: table "orders" does not exist
29:ERROR: table "enduser_license" does not exist
33:ERROR: table "item" does not exist
37:ERROR: Relation "product_version" does not exist
38:ERROR: table "product_version" does not exist
43:ERROR: table "ordered_item" does not exist

but each and every one of these was created via CREATE TABLE

I don't understand why Postgres thinks I am creating a relation _and_ I
don't know what it considers a relation to be. Create stmts follow:

/*================================================= =========================*/
/*
Tables */
/*================================================= =========================*/

DROP TABLE country;
CREATE TABLE country (
country_id VARCHAR(3) PRIMARY KEY,

country VARCHAR(80)
);

DROP TABLE customer;
CREATE TABLE customer (
customer_id SERIAL PRIMARY KEY,
country_id VARCHAR(3) REFERENCES country(country_id),

name VARCHAR(100) NOT NULL,
companyname VARCHAR(100) NOT NULL,
address1 VARCHAR(100) NOT NULL,
address2 VARCHAR(100) NOT NULL,
city VARCHAR(100) NOT NULL,
zipcode VARCHAR(10) NOT NULL,
state VARCHAR(10) NOT NULL,

phone VARCHAR(20),
fax VARCHAR(20),
email VARCHAR(100),
vatid VARCHAR(20)
);

DROP TABLE product;
CREATE TABLE product (
product_id SERIAL PRIMARY KEY,

productdesc VARCHAR(100) NOT NULL,
productname VARCHAR(100) NOT NULL
);

DROP TABLE license;
CREATE TABLE license (
license_id SERIAL PRIMARY KEY,

lickey VARCHAR(80) NOT NULL,
liccode VARCHAR(80) NOT NULL
);

DROP TABLE enduser;
CREATE TABLE enduser (
enduser_id SERIAL PRIMARY KEY,
customer_id INTEGER REFERENCES customer(customer_id),

name VARCHAR(40),
companyname VARCHAR(40)
);

DROP TABLE orders;
CREATE TABLE orders (
orders_id SERIAL PRIMARY KEY,
country_id VARCHAR(3) REFERENCES country(country_id),
customer_id INTEGER REFERENCES customer(customer_id),

name VARCHAR(100) NOT NULL,
companyname VARCHAR(100) NOT NULL,
address1 VARCHAR(100) NOT NULL,
address2 VARCHAR(100) NOT NULL,
city VARCHAR(100) NOT NULL,
state VARCHAR(10) NOT NULL,
zipcode VARCHAR(10) NOT NULL,

orderdate DATE,
phone VARCHAR(20),
fax VARCHAR(20),
email VARCHAR(100),
vatid VARCHAR(20),
refno VARCHAR(100),
promotion VARCHAR(100)
);

DROP TABLE enduser_license;
CREATE TABLE enduser_license (
license_id INTEGER REFERENCES license(license_id),
enduser_id INTEGER REFERENCES enduser(enduser_id),

PRIMARY KEY (license_id, enduser_id)
);

DROP TABLE item;
CREATE TABLE item (
item_id SERIAL,
product_version_id INTEGER REFERENCES
product_version(product_version_id),

active INTEGER NOT NULL,
itemname VARCHAR(100) NOT NULL,
unitprice DECIMAL,
numberoflic INTEGER,

PRIMARY KEY (item_id, product_version_id)
);

DROP TABLE product_version;
CREATE TABLE product_version (
product_version_id SERIAL PRIMARY KEY,
product_id INTEGER REFERENCES product(product_id)
);

DROP TABLE ordered_item;
CREATE TABLE ordered_item (
orders_id INTEGER REFERENCES orders(orders_id),
item_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,

quantity INTEGER NOT NULL,
product_version_id VARCHAR(10),
unitprice DECIMAL,

PRIMARY KEY (orders_id, item_id, product_id)
);
/*================================================= =========================*/
/*
Indexes */
/*================================================= =========================*/
/*================================================= =========================*/
/*
Procedures */
/*================================================= =========================*/

/*================================================= =========================*/
/*
Triggers */
/*================================================= =========================*/

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #1
3 11338
On Thu, Oct 09, 2003 at 05:50:48AM -0700, Terrence Brannon wrote:
I don't know what Postgres considers a relation and had no intention of
creating one when piping my schema to it... I always DROP TABLE before
CREATE TABLE, so here are the ERRORS emitted when building the database:


Well, when you do a DROP TABLE and there's no table with the name you
give, the system is right in giving you a "table foo does not exist".
However, when you create a foreign key to a table that doesn't exist
(because you are creating it further down in your script), the system
doesn't know it is a table (it could be a view, for example). So it
falls back to using the more general term, "relation".

"Relation" means, in Postgres terms, "anything that can have a pg_class
entry". This means system tables and views, regular tables and views,
indexes, sequences, TOAST tables and special relations like pg_xactlock
if I'm not mistaken.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Estoy de acuerdo contigo en que la verdad absoluta no existe...
El problema es que la mentira sí existe y tu estás mintiendo" (G. Lama)

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #2
Terrence Brannon writes:
I don't understand why Postgres thinks I am creating a relation _and_ I
don't know what it considers a relation to be.


In the context of relational databases, relation means the same thing as
table. Because of some implementation artifacts, PostgreSQL internally
treats tables, views, indexes, and sequences alike to some extent and
refers to all of them together as relations. So when you see an error
message telling you that a relation was not found, that means PostgreSQL
was looking for a table, a view, an index, or a sequence. This artificial
terminology isn't ideal, but it creates few problems in practice.

--
Peter Eisentraut pe*****@gmx.net
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #3
On Thu, 2003-10-09 at 13:50, Terrence Brannon wrote:
I don't know what Postgres considers a relation and had no intention of
creating one when piping my schema to it... I always DROP TABLE before
CREATE TABLE, so here are the ERRORS emitted when building the database:

3:ERROR: table "country" does not exist
6:ERROR: table "customer" does not exist
11:ERROR: table "product" does not exist
15:ERROR: table "license" does not exist
19:ERROR: table "enduser" does not exist
24:ERROR: table "orders" does not exist
29:ERROR: table "enduser_license" does not exist
33:ERROR: table "item" does not exist
All these are errors when you DROP a table that does not yet exist.
37:ERROR: Relation "product_version" does not exist
This is your attempt to have a foreign key reference to product_version
from table "item", when product_version does not yet exist.
38:ERROR: table "product_version" does not exist
43:ERROR: table "ordered_item" does not exist
and again, you are dropping these tables before they exist.
but each and every one of these was created via CREATE TABLE
but only _after_ you try to drop them (and your attempt to create "item"
will have failed because of the bad foreign key reference).
I don't understand why Postgres thinks I am creating a relation _and_ I
don't know what it considers a relation to be. Create stmts follow:


A table is a relation but a relation is not necessarily a table, A view
is a relation. However, the error message for your bad foreign key is
misleading because a foreign key must reference a table, not a relation:

junk=# create view aaa as select * from xxx union select * from zzz;
CREATE VIEW
junk=# create table bbb (id serial, aid integer references aaa(id));
NOTICE: CREATE TABLE will create implicit sequence "bbb_id_seq" for
"serial" column "bbb.id"
ERROR: referenced relation "aaa" is not a table

--
Oliver Elphick Ol************@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Every good gift and every perfect gift is from above,
and cometh down from the Father of lights, with whom
is no variableness, neither shadow of turning."
James 1:17
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2881
by: Sharon | last post by:
I have two tables in the DataSet, the first present rooms and the other furniture kinds. Furniture kind, like chare, can be in more then one room. And specific room can contain more then one...
7
3816
by: Wayne Brantley | last post by:
I have found what appears to be an error in streaming with Datasets. It causes an error of 'Cannot find relation 0' when recreating the dataset from a stream. Here is how you reproduce it. ...
2
1931
by: jaYPee | last post by:
I have tried almost everything I know but still I can't find a way on how to resolve this problem. I'm using ImportRow to copy some record from 1 table to another table. Here are my code that...
7
2695
by: Juris Krumins | last post by:
I have a problem with postgresql tables. periodicaly, I would say frequently about 5-10 time per hour i have such errors in my server log file: 2004-04-14 12:23:32 ERROR: cache lookup of...
0
1057
by: brookhartc | last post by:
I am working on a program where I am retrieving data from an Access database through one common dataset. I have already put the database connection component on the form as well as the two data...
0
2892
by: Ambica Jain | last post by:
I have a data grid called Files, which has some columns like FileName, Col1, Col2, ... , Col8. Then i have a combobox which allows user to select from Col1 to Col8 and based on this selection, i...
1
1457
by: Ginger Estherskip | last post by:
I'm setting up a dataset using the GUI to have a Parent Data Table and a few Child Data Tables. I then have a form that uses that dataset, and I can fill the appropriate datatables et. al., but...
4
5097
bugboy
by: bugboy | last post by:
I'm inserting a new word into table 'w' and a definition into table 'c' which are linked in table 's' which is the relation table for the many to many relationship between 'w' and 'c'. I've been...
9
1512
by: Miro | last post by:
VS2008 I have created 3 tables. Vendors Customers PhoneNumbers each have their own key Vendor has: VendorID - int unique identifier Customer has: CustomerID - int unique identifier
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6735
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2992
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.