Thread: Can I get Field informations from system tables?
Hi!
I must get informations about the tables.
For example:
Tnnn:
1. [Field Name, Type, Size, NotNull]
2. [Field Name, Type, Size, NotNull]
...
The test table is this:
CREATE TABLE testfields
(
fbigint bigint NOT NULL,
fbool boolean,
fchar character(100),
fcharv character varying(100),
fdate date,
fdouble double precision,
fint integer,
fnum numeric,
fmemo text,
ftimez time with time zone,
ftime time without time zone,
ftimestampz timestamp with time zone,
ftimestamp timestamp without time zone,
fserial serial NOT NULL,
CONSTRAINT testfields_pkey PRIMARY KEY (fserial)
)
When I see Pygresql, I got only these informations:
Command line: C:\Python25\python.exe c:\PGDB_T~1.PY
Working directory: c:\
Timeout: 0 ms
[{'FSERIAL': 1, 'FMEMO': 'fdsf sdf dsfds sdd sfsdfsdfsd dsfsd sdfsd ssdsd sdsd', 'FCHAR': 'alma ', 'FBIGINT': 1L, 'FNUM': Decimal("454.3234"), 'FTIMESTAMPZ': '1999-01-01 10:10:10+01', 'FINT': 43545, 'FTIMEZ': '10:10:10+02', 'FDOUBLE': 4.5656656, 'FTIME': '10:10:10', 'FCHARV': 'alma', 'FDATE': '1999-03-25', 'FTIMESTAMP': '1999-01-01 10:10:10', 'FBOOL': True}]
('fbigint', 'int8', None, 8, None, None, None)
('fbool', 'bool', None, 1, None, None, None)
('fchar', 'bpchar', None, -1, None, None, None)
('fcharv', 'varchar', None, -1, None, None, None)
('fdate', 'date', None, 4, None, None, None)
('fdouble', 'float8', None, 8, None, None, None)
('fint', 'int4', None, 4, None, None, None)
('fnum', 'numeric', None, -1, None, None, None)
('fmemo', 'text', None, -1, None, None, None)
('ftimez', 'timetz', None, 12, None, None, None)
('ftime', 'time', None, 8, None, None, None)
('ftimestampz', 'timestamptz', None, 8, None, None, None)
('ftimestamp', 'timestamp', None, 8, None, None, None)
('fserial', 'int4', None, 4, None, None, None)
Process "Python Interpeter" terminated, ExitCode: 00000000
The main problem that I don't see the size of the char/varchar fields, and I don't determine that int field is serial or not?
Thanks for the help:
dd
I must get informations about the tables.
For example:
Tnnn:
1. [Field Name, Type, Size, NotNull]
2. [Field Name, Type, Size, NotNull]
...
The test table is this:
CREATE TABLE testfields
(
fbigint bigint NOT NULL,
fbool boolean,
fchar character(100),
fcharv character varying(100),
fdate date,
fdouble double precision,
fint integer,
fnum numeric,
fmemo text,
ftimez time with time zone,
ftime time without time zone,
ftimestampz timestamp with time zone,
ftimestamp timestamp without time zone,
fserial serial NOT NULL,
CONSTRAINT testfields_pkey PRIMARY KEY (fserial)
)
When I see Pygresql, I got only these informations:
Command line: C:\Python25\python.exe c:\PGDB_T~1.PY
Working directory: c:\
Timeout: 0 ms
[{'FSERIAL': 1, 'FMEMO': 'fdsf sdf dsfds sdd sfsdfsdfsd dsfsd sdfsd ssdsd sdsd', 'FCHAR': 'alma ', 'FBIGINT': 1L, 'FNUM': Decimal("454.3234"), 'FTIMESTAMPZ': '1999-01-01 10:10:10+01', 'FINT': 43545, 'FTIMEZ': '10:10:10+02', 'FDOUBLE': 4.5656656, 'FTIME': '10:10:10', 'FCHARV': 'alma', 'FDATE': '1999-03-25', 'FTIMESTAMP': '1999-01-01 10:10:10', 'FBOOL': True}]
('fbigint', 'int8', None, 8, None, None, None)
('fbool', 'bool', None, 1, None, None, None)
('fchar', 'bpchar', None, -1, None, None, None)
('fcharv', 'varchar', None, -1, None, None, None)
('fdate', 'date', None, 4, None, None, None)
('fdouble', 'float8', None, 8, None, None, None)
('fint', 'int4', None, 4, None, None, None)
('fnum', 'numeric', None, -1, None, None, None)
('fmemo', 'text', None, -1, None, None, None)
('ftimez', 'timetz', None, 12, None, None, None)
('ftime', 'time', None, 8, None, None, None)
('ftimestampz', 'timestamptz', None, 8, None, None, None)
('ftimestamp', 'timestamp', None, 8, None, None, None)
('fserial', 'int4', None, 4, None, None, None)
Process "Python Interpeter" terminated, ExitCode: 00000000
The main problem that I don't see the size of the char/varchar fields, and I don't determine that int field is serial or not?
Thanks for the help:
dd
On Thu, Aug 13, 2009 at 05:20:22PM +0200, Durumdara wrote: > I must get informations about the tables. > For example: > Tnnn: > 1. [Field Name, Type, Size, NotNull] > 2. [Field Name, Type, Size, NotNull] I'd recommend either using the standard defined information_schema[1] or playing around with running psql with -E. -- Sam http://samason.me.uk/ [1] http://www.postgresql.org/docs/current/static/information-schema.html