Re: [GENERAL] brain-teaser with CONSTRAINT - any SQL experts?

2005-10-09 Thread Miles Keaton
Uwe said: how about using 2 tables with according unique/primary key constraints and a view to actually access the data (mixing the 2 tables into one) ? Oliver said: Create a separate table with the two columns name and isbn which are that table's primary key; on the main table, create a

Re: [GENERAL] brain-teaser with CONSTRAINT - any SQL experts?

2005-10-09 Thread Miles Keaton
I would create a multi-column unique index on the table. This should solve the problem mentioned although you may still have an integrity issue if a book name is mistyped. Hm? This sounds promising, except it's the exact opposite of what I need. Is this what you meant? CREATE TABLE

Re: [GENERAL] brain-teaser with CONSTRAINT - any SQL experts?

2005-10-09 Thread Miles Keaton
; END IF; RETURN NEW; END; $function$ LANGUAGE plpgsql; CREATE TRIGGER ndi BEFORE INSERT OR UPDATE ON books FOR EACH ROW EXECUTE PROCEDURE non_duplicated_isbn(); On 10/8/05, Miles Keaton [EMAIL PROTECTED] wrote: I'm stuck on a brain-teaser with CONSTRAINT: Imagine a table like lineitems

[GENERAL] possible bug : pg_dump does not include ALTER DATABASE SET search_path

2005-10-08 Thread Miles Keaton
possible bug : pg_dump does not include ALTER DATABASE ... SET search_path TO ... pg_dumpall does include it. pg_dump only includes the runtime SET search_path, but not the permanent ALTER DATABASE part is this intentional?

[GENERAL] brain-teaser with CONSTRAINT - any SQL experts?

2005-10-08 Thread Miles Keaton
I'm stuck on a brain-teaser with CONSTRAINT: Imagine a table like lineitems in a bookstore - where you don't need an ISBN to be unique because a book will be in buying history more than once. But you DO need to make sure that the ISBN number is ONLY matched to one book name - NOT to more than

[GENERAL] pgcrypto : how to get SHA1(string) as a 40-char string, NOT binary string?

2005-07-13 Thread Miles Keaton
I have the contrib/pgcrypto installed. I want to get the 40-character hash from SHA1 Example: SELECT digest('blue', 'sha1') would be: 4c9a82ce72ca2519f38d0af0abbb4cecb9fceca9 I was surprised and disappointed to get a binary-hash back. Does anyone know how to get the regular 40-character string

[GENERAL] PL/pgSQL function to validate UPC and EAN barcodes - works! Improvements?

2005-06-24 Thread Miles Keaton
I've made a PL/pgSQL function to validate UPC and EAN barcodes. It works correctly, but is a little ugly. Wondering if any PL/pgSQL experts can offer some suggestions. (I'm new to PL/pgSQL.) Main questions: #1 - I wanted to add a 0 to the front of the barcode if it was only 12 characters long.

[GENERAL] PostgreSQL users, tell your tale on Slashdot

2005-03-21 Thread Miles Keaton
Slashdot story just posted a few minutes ago: http://slashdot.org/article.pl?sid=05/03/21/1635210 I've been using PostgreSQL for years on small projects, and I have an opportunity to migrate my company's websites from Oracle to an open-source alternative. It would be good to be able to show the

Re: [GENERAL] pg_dump dumping data in order? (used to in 7.4 but not now in 8?)

2005-02-12 Thread Miles Keaton
use --disable-triggers Hey! Cool. Worked. Thanks! ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

[GENERAL] pg_dump dumping data in order? (used to in 7.4 but not now in 8?)

2005-02-11 Thread Miles Keaton
When I do a pg_dump, (--data-only), PG7 used to dump the data out in order, so that all foreign-key checks worked correctly when loading the data back in. Now it seems with PG8 it's dumping it completely out of order (one of my completely foreign-key join tables first!) - and I can't get it to

[GENERAL] possible to DELETE CASCADE?

2004-12-30 Thread Miles Keaton
Is it possible for a query to delete a record and all of its foreign-key dependents? I see DROP CASCADE, but not a DELETE CASCADE. What I'm trying to do: I have a clients table. I have many different tables that use the clients.id as a foreign key. When I delete a client, I want it to delete all

Re: [GENERAL] possible to DELETE CASCADE?

2004-12-30 Thread Miles Keaton
On Thu, 30 Dec 2004 11:10:38 -0800, I wrote: Is it possible for a query to delete a record and all of its foreign-key dependents? Sorry - to be more clear : I like having my foreign keys RESTRICT from this kind of cascading happening automatically or accidently. So I'm looking for a query

Re: [GENERAL] possible to DELETE CASCADE?

2004-12-30 Thread Miles Keaton
Cool. Thanks for all the advice, guys. I'll just keep my script manually deleting dependencies, then. It gives me peace of mind. :-) ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

[GENERAL] could not create semaphores : No space left on device = FreeBSD port install error!

2004-12-15 Thread Miles Keaton
I'm posting this here for search-engine's sake, so future people having this same problem can find the solution here. After installing PostgreSQL from FreeBSD's ports, and running su - pgsql -c initdb for the first time, I got this common error: could not create semaphores : No space left on

[GENERAL] why use SCHEMA? any real-world examples?

2004-11-24 Thread Miles Keaton
I just noticed PostgreSQL's schemas for my first time. (http://www.postgresql.org/docs/current/static/ddl-schemas.html) I Googled around, but couldn't find any articles describing WHY or WHEN to use schemas in database design. Since the manual says HOW, could anyone here who has used schemas

[GENERAL] list fieldnames in table? (from PHP)

2004-10-25 Thread Miles Keaton
Is there a simple way to list fieldnames in a table, from PHP? When on the command-line, I just do \d tablename But how to get the fieldnames from PHP commands? ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an

[GENERAL] interesting! a sequence clashes with data already in that table

2004-10-08 Thread Miles Keaton
Here's an interesting problem! When a sequence clashes with data already in that table: CREATE TABLE clients ( id serial NOT NULL PRIMARY KEY UNIQUE, name varchar(64)); -- import OLD clients, with their original ID#... INSERT INTO clients VALUES (3, 'Dave'); INSERT INTO clients VALUES (4,

[GENERAL] when to use NULL and when to NOT NULL DEFAULT ''

2004-10-07 Thread Miles Keaton
PG peeps: What's the prevailing wisdom best-practice advice about when to let a varchar (or any) column be NULL, and when to make it NOT NULL DEFAULT '' (or '-00-00' or whatever) - in PostgreSQL? {Moving to PG from MySQL where we were always advised to use NOT NULL to save a byte or

[GENERAL] how to encode/encrypt a string

2004-09-30 Thread Miles Keaton
still doing my switch from MySQL to PgSQL, and can't figure out what the comparable function would be for this: In MySQL, to store a big secret (like a credit card number) in the database that I didn't want anyone to be able to see without knowing the salt/password value, I would do this into a

[GENERAL] books/sites for someone really learning PG's advanced features?

2004-09-24 Thread Miles Keaton
I'm switching to PostgreSQL from MySQL. Using the SAMs book called PostgreSQL which has been great to skim the surface of the differerences. I had never even heard of things like triggers, views, and foreign keys before. Any recommended books or websites (or exercises) that would really help

[GENERAL] brand new user - should I start with v8?

2004-09-21 Thread Miles Keaton
I'm a brand new PostgreSQL user -- just started today (though I've used MySQL for years). Should I just start learning with version 8, since I'm sure I won't launch any real live public projects with PostgreSQL for another few months? Any estimate when 8.0.0 will be final production-ready?