[SQL] Create Table Problem

2008-06-13 Thread Shavonne Marietta Wijesinghe
Hello

I'm having some trouble checking if a table exist before i create it. 

Example:

SELECT * FROM distributors

IF (table not found) THEN
CREATE TABLE distributors (
did integer,
namevarchar(40),
UNIQUE(name)
);
END IF

If i have a table like the above how can i identify if the table exists or not?

Thank You.

Shavonne Wijesinghe


Re: [SQL] Create Table Problem

2008-06-13 Thread Volkan YAZICI
"Shavonne Marietta Wijesinghe" <[EMAIL PROTECTED]> writes:
> IF (table not found) THEN
> CREATE TABLE distributors (
> did integer,
> namevarchar(40),
> UNIQUE(name)
> );
> END IF

Assuming you're in a procedure (above code snippet looks to be executed
within a PL/pgsql procedure):

  IF EXISTS (SELECT 1
   FROM information_schema.tables
  WHERE table_schema = 'public' AND
table_name   = 'distributors)
THEN ...
 END IF;


Regards.

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


[SQL] How to manage category-ids as array-fields ?

2008-06-13 Thread Andreas

Hi,

I get from an outside source tables as simple textfiles to import.
Those are obviously results of views with joined tables.

Among the normal stuff are columns that have one or a list of id-numbers 
devided by a semicolon.

In the next column there is the corresponding text for this ids.

It looks like this:
17, ... ,  "1; 2;", "cat; mouse;", ...
23, ...,  "3;", "dog;", ...
42, ..., "2; 7;", "mouse; horse;", ...

Obviously the meaning is that some entity has those listed attributes. 
Most likely they are stored as a n:m-relation like:

17, 1
17, 2
23, 3
42, 2
42, 7

Is there a way to reproduce the output in the form above (as array) ?

Is there a way to import the data in the form above, so it gets neately 
stored in a n:m ?


Is it seen as a conceptual good solution to store such information 
within a text-column or array?

I'd rather doubt that PG would watch the integrity of those ids then.




--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql