pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedCheck for table existence
4+ messages / 4 participants
[nested] [flat]
* Check for table existence
@ 2001-11-28 21:47 Michael Knudsen <mk267673@but.auc.dk>
2001-11-29 14:17 ` Re: Check for table existence Alexander Steinert <stony8@gmx.de>
2001-11-29 15:58 ` Re: Check for table existence Haller Christoph <ch@rodos.fzk.de>
2001-11-30 02:05 ` Re: Check for table existence Roberto Mello <rmello@cc.usu.edu>
0 siblings, 3 replies; 4+ messages in thread
From: Michael Knudsen @ 2001-11-28 21:47 UTC (permalink / raw)
To: pgsql-sql
Hi group
First, let me say that I am new to postgres. I used MySQL before, but..
ehm..
I am trying to do a small program (in C), and I have stumbled on to some
problems:
1. How can I check if a given table exists?
2. How can I check if a given existing table has the right layout? (Correct
column names and types)
Currently, I check using something like:
select * from giventable limit 0;
but that only helps checking if the table exists and if the number of
columns is correct. I'm sure, there must be a smoother way to do this, but I
cannot seem to find it. Anyone out there with good ideas?
M.
--
Rumour is information distilled so finely that it can filter through
anything.
-- (Terry Pratchett, Feet of Clay)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Check for table existence
2001-11-28 21:47 Check for table existence Michael Knudsen <mk267673@but.auc.dk>
@ 2001-11-29 14:17 ` Alexander Steinert <stony8@gmx.de>
2 siblings, 0 replies; 4+ messages in thread
From: Alexander Steinert @ 2001-11-29 14:17 UTC (permalink / raw)
To: pgsql-sql
> First, let me say that I am new to postgres. I used MySQL before, but..
> ehm..
Welcome.
> 1. How can I check if a given table exists?
> 2. How can I check if a given existing table has the right
> layout? (Correct column names and types)
http://archives2.us.postgresql.org/pgsql-sql/2001-07/msg00319.php
and
http://archives2.us.postgresql.org/pgsql-sql/2001-07/msg00403.php
will show you the way to go.
Stony
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Check for table existence
2001-11-28 21:47 Check for table existence Michael Knudsen <mk267673@but.auc.dk>
@ 2001-11-29 15:58 ` Haller Christoph <ch@rodos.fzk.de>
2 siblings, 0 replies; 4+ messages in thread
From: Haller Christoph @ 2001-11-29 15:58 UTC (permalink / raw)
To: mk267673@but.auc.dk; +Cc: pgsql-sql
Hi Michael,
>
>
> 1. How can I check if a given table exists?
> 2. How can I check if a given existing table has the right layout? (Correct
> column names and types)
>
Try this
create view my_tbldescription as
select
u.usename, t.typname AS tblname,
a.attname, a.atttypid, n.typname AS atttypname,
int4larger(a.attlen, a.atttypmod - 4) AS atttyplen,
a.attnotnull, a.attnum
from pg_user u, pg_type t, pg_attribute a, pg_type n
where u.usesysid = t.typowner
and t.typrelid = a.attrelid and t.typtype = 'c' and not (t.typname ~* 'pg_')
and n.typelem = a.atttypid
and substr(n.typname, 1, 1) = '_'
and a.attnum > 0 ;
select * from my_tbldescription order by 1,2,8 ;
It should tell you all you want to know.
Regards, Christoph
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Check for table existence
2001-11-28 21:47 Check for table existence Michael Knudsen <mk267673@but.auc.dk>
@ 2001-11-30 02:05 ` Roberto Mello <rmello@cc.usu.edu>
2 siblings, 0 replies; 4+ messages in thread
From: Roberto Mello @ 2001-11-30 02:05 UTC (permalink / raw)
To: Michael Knudsen <mk267673@but.auc.dk>; +Cc: pgsql-sql
On Wed, Nov 28, 2001 at 10:47:42PM +0100, Michael Knudsen wrote:
> Hi group
>
> First, let me say that I am new to postgres. I used MySQL before, but..
> ehm..
>
> I am trying to do a small program (in C), and I have stumbled on to some
> problems:
>
> 1. How can I check if a given table exists?
> 2. How can I check if a given existing table has the right layout? (Correct
> column names and types)
There's a function to check for a table's existance in the PostgreSQL
Cookbook (http://www.brasileiro.net/postgres/)
-Roberto
--
+----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+
Roberto Mello - Computer Science, USU - http://www.brasileiro.net
http://www.sdl.usu.edu - Space Dynamics Lab, Developer
Daddy, why doesn't this magnet pick up this floppy?
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2001-11-30 02:05 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-11-28 21:47 Check for table existence Michael Knudsen <mk267673@but.auc.dk>
2001-11-29 14:17 ` Alexander Steinert <stony8@gmx.de>
2001-11-29 15:58 ` Haller Christoph <ch@rodos.fzk.de>
2001-11-30 02:05 ` Roberto Mello <rmello@cc.usu.edu>
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