Question

I'm doing a tastrade schema off the data our lecturers gave us. I'm using the SQL Pane to build the table and not the graphical userface (of PgAdminIII)

I have these 2:

12   MAX_ORDER_AMT Curr       8      4    max_order_amt > min_order_amt
13   MIN_ORDER_AMT.Curr       8      4    max_order_amt > min_order_amt
...
...

in order to create it I used [partial code]

"Max_Order_Amt" money,
"Min_Order_Amt" money,
...
...

In order to add the Max_Order_amt > min_order_amt constraint, what do I have to use?

I tried using "max_order_amt > min_order_amt" but it failed.

Thanks a lot for your help

Language Used: PostegreSQL

Graphical Userface PgAdminIII

EDIT: This is the FULL CREATE TABLE Code

CREATE TABLE oltp.customer
("Customer_ID" character (6) NOT NULL,
"Company_Name" character (40) NOT NULL,
"Contact_Name" character (30) NOT NULL,
"Address" character (60),
"City" character (15),
"Region" character(15),
"Postal_Code" character(10),
"Phone" character(24),
"Fax" character(24),
"Max_Order_Amt" money CHECK (Max_Order_Amt > Min_Order_Amt),
"Min_Order_Amt" money CHECK (Max_Order_Amt > Min_Order_Amt),
"Discount" numeric(2) CHECK (Discount >=0),
"Sales_Region" character(4),
CONSTRAINT customers_pkey PRIMARY KEY ("Customer_ID"))
WITH 
( OIDS = FALSE);
alter table oltp.customer
OWNER to postgres;

ERROR:  column "max_order_amt" does not exist

********** Error **********

ERROR: column "max_order_amt" does not exist
SQL state: 42703

This Below is the Tastrade Schema

CUSTOMER
(Customer Information)
Beware of updating or deleting instances from this table as other tables refer to this table’s PK
Number of data records:       92      
Fd   Field Name    Type   Width    Dec   Notes
 1   CUSTOMER_ID   Char       6          PK, system generated, not null
 2   COMPANY_NAME  Char      40          not null
 3   CONTACT_NAME  Char      30          not null
 4   CONTACT_TITLE Char      40          
 5   ADDRESS       Char      60          
 6   CITY          Char      15          
 7   REGION        Char      15          
 8   POSTAL_CODE   Char      10          
 9   COUNTRY       Char      15          
10   PHONE         Char      24          
11   FAX           Char      24          
12   MAX_ORDER_AMT Curr       8      4    max_order_amt > min_order_amt
13   MIN_ORDER_AMT.Curr       8      4    max_order_amt > min_order_amt
14   DISCOUNT      Nume       2           discount >= 0
15   SALES_REGION  Char       4          
** Total **                       302   

In the tastarade Schema Lines 12-14 are giving me the the 'does not exist' error. I have followed the 8.1 manual. It stops at Max_Order_Amt, but when I tried on the others, it gave me the same error

Thx again

Was it helpful?

Solution

Use a check constraint while creating your table like

"Max_Order_Amt" money CHECK (Max_Order_Amt > Min_Order_Amt)

See more about Check constraint here http://www.postgresql.org/docs/8.1/static/ddl-constraints.html

EDIT:

Remove those " double quotes around column name. Try it like below

CREATE TABLE customer
(Customer_ID character (6) NOT NULL,
Company_Name character (40) NOT NULL,
Contact_Name character (30) NOT NULL,
Address character (60),
City character (15),
Region character(15),
Postal_Code character(10),
Phone character(24),
Fax character(24),
Max_Order_Amt money CHECK (Max_Order_Amt > Min_Order_Amt),
Min_Order_Amt money,
Discount numeric(2) CHECK (Discount >=0),
Sales_Region character(4),
 CONSTRAINT customers_pkey PRIMARY KEY (Customer_ID));

See a demo fiddle here http://sqlfiddle.com/#!15/60767

EDIT1:

If you really want to keep " around your column name (for some reason) then make your check constraint looks like below

"Max_Order_Amt" money CHECK ("Max_Order_Amt" > "Min_Order_Amt"),
"Min_Order_Amt" money CHECK ("Max_Order_Amt" > "Min_Order_Amt"),
"Discount" numeric(2) CHECK ("Discount" >=0),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top