[Pgsql-ayuda] columna NOT NULL

Eladio Rodriguez elarod01@hotmail.com
Wed, 30 Apr 2003 21:35:38 -0600


<html><div style='background-color:'><DIV>saludos. </DIV>
<P>excelente, de maravilla,eso era lo que me hacia falta, el SET en al ALTER.</P>
<P>pura vida, mae, como decimos aca en costa rica.</P>
<P>seguiremos en la lucha.</P>
<P>&gt;From: Gunnar Wolf <GWOLF@GWOLF.CX></P>
<DIV></DIV>&gt;To: Eladio Rodriguez <ELAROD01@HOTMAIL.COM>
<DIV></DIV>&gt;CC: Pgsql-ayuda@tlali.iztacala.unam.mx 
<DIV></DIV>&gt;Subject: Re: [Pgsql-ayuda] columna NOT NULL 
<DIV></DIV>&gt;Date: Wed, 30 Apr 2003 18:39:31 -0500 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; &gt; saludos. 
<DIV></DIV>&gt; &gt; erodriguez-#alter table t 
<DIV></DIV>&gt; &gt; erodriguez-#add contraint c_pk primary key (c); 
<DIV></DIV>&gt; &gt; ALTER 
<DIV></DIV>&gt; &gt; erodriguez-# add constraint c_pk primary key (c); 
<DIV></DIV>&gt; &gt; ERROR: Existing attribute "c" cannot be a PRIMARY KEY because it is not marked 
<DIV></DIV>&gt; &gt; NOT NULL 
<DIV></DIV>&gt; &gt; 
<DIV></DIV>&gt; &gt; y efectivamente la columna no esta marcada como NOT NULL, lo que tiene es un 
<DIV></DIV>&gt; &gt; constraint 
<DIV></DIV>&gt; &gt; 
<DIV></DIV>&gt; &gt; erodriguez-# \d t 
<DIV></DIV>&gt; &gt; Table "t" 
<DIV></DIV>&gt; &gt; Column | Type | Modifiers 
<DIV></DIV>&gt; &gt; --------+----------------------+----------- 
<DIV></DIV>&gt; &gt; c | character varying(1) | 
<DIV></DIV>&gt; &gt; Check constraints: "c_not_null" NULL::bool 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Oka... La pones fácil así :-) Te faltaba indicarle que no permitiera 
<DIV></DIV>&gt;nulos. Vamos a ver, hice lo siguiente: 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;gwolf=# CREATE TEMP TABLE asdf (id integer, descr text); 
<DIV></DIV>&gt;CREATE TABLE 
<DIV></DIV>&gt;gwolf=# \d asdf 
<DIV></DIV>&gt; Table "pg_temp_1.asdf" 
<DIV></DIV>&gt; Column | Type | Modifiers 
<DIV></DIV>&gt;--------+---------+----------- 
<DIV></DIV>&gt; id | integer | 
<DIV></DIV>&gt; descr | text | 
<DIV></DIV>&gt;gwolf=# ALTER TABLE asdf ALTER COLUMN id SET NOT NULL; 
<DIV></DIV>&gt;ALTER TABLE 
<DIV></DIV>&gt;gwolf=# ALTER TABLE asdf ADD CONSTRAINT c_pk PRIMARY KEY (id); 
<DIV></DIV>&gt;NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index 'c_pk' for table 'asdf' 
<DIV></DIV>&gt;ALTER TABLE 
<DIV></DIV>&gt;gwolf=# \d asdf 
<DIV></DIV>&gt; Table "pg_temp_1.asdf" 
<DIV></DIV>&gt; Column | Type | Modifiers 
<DIV></DIV>&gt;--------+---------+----------- 
<DIV></DIV>&gt; id | integer | not null 
<DIV></DIV>&gt; descr | text | 
<DIV></DIV>&gt;Indexes: c_pk primary key btree (id) 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;y ya quedó :-) 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; &gt; el comando SET LINESIZE 5000, lo que hace es que cuando el SELECT necesita 
<DIV></DIV>&gt; &gt; presentar los datos mas alla del borde derecho se le puede dar scroll y no te 
<DIV></DIV>&gt; &gt; salen las cosas como: 
<DIV></DIV>&gt; &gt; (...) 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Bueno, eso se lo dejo ya a alguien más ;-) Sin embargo, sí puedo 
<DIV></DIV>&gt;comentar algo: Esto no es algo que cambiarás sobre Postgres, sino que 
<DIV></DIV>&gt;sobre el cliente que estás usando (psql). Puedes asomarte a su fuente en 
<DIV></DIV>&gt;el peor de los casos, está bastante claro. 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Saludos, 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;-- 
<DIV></DIV>&gt;Gunnar Wolf - gwolf@gwolf.cx - (+52-55)5630-9700 ext. 1366 
<DIV></DIV>&gt;PGP key 1024D/8BB527AF 2001-10-23 
<DIV></DIV>&gt;Fingerprint: 0C79 D2D1 2C4E 9CE4 5973 F800 D80E F35A 8BB5 27AF 
<DIV></DIV></div><br clear=all><hr>Add photos to your e-mail with <a href="http://g.msn.com/8HMQEN/2746">MSN 8.</a> Get 2 months FREE*.</html>