pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedshowing the DEFAULT of a field
2+ messages / 2 participants
[nested] [flat]
* showing the DEFAULT of a field
@ 1999-11-05 22:15 Klaus Woelfel <woelfel@mayn.de>
1999-11-06 12:01 ` Re: [SQL] showing the DEFAULT of a field Stoyan Genov <genov@digsys.bg>
0 siblings, 1 reply; 2+ messages in thread
From: Klaus Woelfel @ 1999-11-05 22:15 UTC (permalink / raw)
To: pgsql-sql
Hi,
I'm new to psql and used mysql before. With mysql I could get with "show columns
from table 'table_name'" a table with the rows "Field", "Type", "NULL", "Key",
"Default" and "Extra".
But with "\d 'table_name'" in qsql I get only a table with the rows "Field",
"Type", and "Length". How can I get the other Information for example the
Default or if the field has the primary key?
Klaus Woelfel
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [SQL] showing the DEFAULT of a field
1999-11-05 22:15 showing the DEFAULT of a field Klaus Woelfel <woelfel@mayn.de>
@ 1999-11-06 12:01 ` Stoyan Genov <genov@digsys.bg>
0 siblings, 0 replies; 2+ messages in thread
From: Stoyan Genov @ 1999-11-06 12:01 UTC (permalink / raw)
To: Klaus Woelfel <woelfel@mayn.de>; +Cc: pgsql-sql; genov@lorna.digsys.bg
Hi.
Please look carefully at the sequence of commands:
shell#>createdb tmp
shell#>psql tmp
Welcome to the POSTGRESQL interactive sql monitor:
Please read the file COPYRIGHT for copyright terms of POSTGRESQL
[PostgreSQL 6.5.2 on i386-pc-bsdi4.0.1, compiled by gcc 2.7.2.1]
type \? for help on slash commands
type \q to quit
type \g or terminate with semicolon to execute query
You are currently connected to the database: tmp
tmp=> \d
Couldn't find any tables, sequences or indices!
tmp=> create table test (i int4 primary key, j int4 default 1, t text not
null);
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'test_pkey'
for table 'test'
CREATE
tmp=> \d
Database = tmp
+------------------+----------------------------------+----------+
| Owner | Relation | Type |
+------------------+----------------------------------+----------+
| genov | test | table |
| genov | test_pkey | index |
+------------------+----------------------------------+----------+
tmp=> \d test
Table = test
+----------------------------------+----------------------------------+-----
--+
| Field | Type |
Length|
+----------------------------------+----------------------------------+-----
--+
| i | int4 not null |
4 |
| j | int4 default 1 |
4 |
| t | text not null |
var |
+----------------------------------+----------------------------------+-----
--+
Index: test_pkey
tmp=> \q
shell#>pg_dump tmp
\connect - genov
CREATE TABLE "test" (
"i" int4 NOT NULL,
"j" int4 DEFAULT 1,
"t" text NOT NULL);
COPY "test" FROM stdin;
\.
CREATE UNIQUE INDEX "test_pkey" on "test" using btree ( "i" "int4_ops" );
shell#>
So, I hope you see how restrictions upon fields are expressed and created.
The probably confusing stuff is about the primary key. Primary keys are
const-
ructed using unique indices upon the fields you say "primary key" about
during
the creation of a table. These unique indices will not allow a duplicate
value
in the field, which is, technically speaking, the primary goal of a primary
key
field.
Watch this:
tmp=> insert into test (i) values (1);
ERROR: ExecAppend: Fail to add null value in not null attribute t
tmp=> insert into test (i,t) values (1,'a line');
INSERT 31375 1
tmp=> insert into test (i,t) values (1,'another line');
ERROR: Cannot insert a duplicate key into a unique index
tmp=> \q
This is it. If something is unclear, do write back.
Stoyan Genov
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1999-11-06 12:01 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-11-05 22:15 showing the DEFAULT of a field Klaus Woelfel <woelfel@mayn.de>
1999-11-06 12:01 ` Stoyan Genov <genov@digsys.bg>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox