Обсуждение: insert and heritage...
hi everyone.... i'm having a slight problem understanding something....
I've bought a book about programming postgres, and there's a part
concerning heritage.... so as i need to implement something like this in
my work, i'm testing it.
I have a database called project (no matter the name)... It contains
several tables. One of them is called "equipements" and has 5 columns :
CREATE TABLE equipements (id serial, adresseMac macaddr NOT NULL UNIQUE,
adresseIp cidr, etat char, administrable bool,primary key(id));
so i entered a first value in this table with :
INSERT INTO equipements (administrable,adresseip,adressemac,etat) VALUES
('false','192.168.0.1','FF:EE:DD:CC:BB:AA','0')\g
so far so good.
now, i have another table called "postetravail" that inherits from
"equipements".... it was created like this :
CREATE TABLE postetravail (nom char) INHERITS (equipements);
i want this table to have quite the same columns as "equipments", but
all i need for this entity is a name. When i look every column with sun
one studio (for example), i see them right...
my first trouble comes from the state of "id", that is no more a primary
key in "postetravail" while it was in "equipements", and it's located
between "etat" and "nom"
now i have
administrable
adresseip
adressemac
etat
id
nom
while i was awaiting :
id (primary key)
administrable
adresseip
adressemac
etat
nom
the next problem concerns the insert :
INSERT INTO postetravail (administrable,adresseip,adressemac,etat,nom)
VALUES ('false','192.168.0.2','FF:EE:DD:CC:BB:AB','1','big')\g
ERROR: value too long for type character(1)
What is the problem.... I have the values in the correct order (i
guess), and i keep having this error... i tried to add the id column in
the insert, but it did not solve the problem....
Does somebody have clues for these 2 problems ?
regards
Stephane
hi Len,
Len Morgan a écrit:
>the next problem concerns the insert :
>
>INSERT INTO postetravail (administrable,adresseip,adressemac,etat,nom)
>VALUES ('false','192.168.0.2','FF:EE:DD:CC:BB:AB','1','big')\g
>ERROR: value too long for type character(1)
>
>Administrable is defined as char (i.e., length of one) and 'false' is 5
>characters. You probably want type Boolean instead of character.
>
>
Sure ;-)
i want boolean type, that's why the parent table "equipement" is
declared with :
CREATE TABLE equipements (id serial, adresseMac macaddr NOT NULL UNIQUE,
adresseIp cidr, etat char, administrable bool,primary key(id));
CREATE TABLE postetravail (nom char) INHERITS (equipements);
from the dump file i've made, i have the result :
CREATE TABLE equipements (
id serial NOT NULL,
adressemac macaddr NOT NULL,
adresseip cidr,
etat character(1),
administrable boolean
);
CREATE TABLE postetravail (
nom character(1)
)
INHERITS (equipements);
COPY postetravail (id, adressemac, adresseip, etat, administrable, nom)
FROM stdin;
and there administrable is boolean, so why postetravail that inherits
from equipement should not be the same ? am i doing wrong with the
parameters order ?
Stephane
stephane parenton a écrit:
> hi Len,
>
> Len Morgan a écrit:
>
>> the next problem concerns the insert :
>>
>> INSERT INTO postetravail
>> (administrable,adresseip,adressemac,etat,nom) VALUES
>> ('false','192.168.0.2','FF:EE:DD:CC:BB:AB','1','big')\g
>> ERROR: value too long for type character(1)
>>
>> Administrable is defined as char (i.e., length of one) and 'false' is 5
>> characters. You probably want type Boolean instead of character.
>>
>>
> CREATE TABLE postetravail (
> nom character(1)
> )
> INHERITS (equipements);
hemmmmmmm.... let's say i'd better read my scripts before posting !!!!!!
if i tell the name to be stored only with char(1), it won't fit my needs
when i try to enter a longer name.... ;-)
sorry !!!! my fault !
Stephane