Re: [SQL] surrogate key or not?

2004-07-22 Thread sad
I want to add some notes > create table diagnosis ( > pk serial primary key, > fk_patient integer > not null > references patient(pk) > on update cascade > on delete cascade, > narrative text > not null, > unique(fk_patient, narrative) > ); 1) a seque

Re: [SQL] LIKE on index not working

2004-07-22 Thread Chris Cox
Hi Peter, Thanks for the tip. The locale we're using is en_US.UTF-8. From my limited knowledge of locales, that's a non-C one isn't it? Am I right in saying that to fix it I need to initdb again with a C locale? How do I go about doing that on an environment with some 132 databases? What a pai

Re: [SQL] Converting a plperlu function to a plpgsql function

2004-07-22 Thread Tom Lane
Jeff Eckermann <[EMAIL PROTECTED]> writes: >> Second line: >> >> if ($r=~/^-([0-9]?)([A-z_]+)/) >> { >> my $locid = $1; >> my $table = $2; > PostgreSQL doesn't offer capturing parentheses. Hm? See the substring function: regression=# select substring('foobar' from 'o(.)a'); substrin

Re: [SQL] Converting a plperlu function to a plpgsql function

2004-07-22 Thread Devin Whalen
On Thu, 2004-07-22 at 15:09, Jeff Eckermann wrote: > --- Joe Conway <[EMAIL PROTECTED]> wrote: > > Devin Whalen wrote: > > > First line: > > > my @active_tables=split(/,/,$tables); > > > > > > Is there anyway to split a variable like the perl > > split above? > > > > I'm no perl guru, but in 7.4

Re: [SQL] Converting a plperlu function to a plpgsql function

2004-07-22 Thread Jeff Eckermann
--- Joe Conway <[EMAIL PROTECTED]> wrote: > Devin Whalen wrote: > > First line: > > my @active_tables=split(/,/,$tables); > > > > Is there anyway to split a variable like the perl > split above? > > I'm no perl guru, but in 7.4 I believe this does > what you're looking for: > > regression=# sele

Re: [SQL] Converting a plperlu function to a plpgsql function

2004-07-22 Thread Joe Conway
Devin Whalen wrote: First line: my @active_tables=split(/,/,$tables); Is there anyway to split a variable like the perl split above? I'm no perl guru, but in 7.4 I believe this does what you're looking for: regression=# select string_to_array('1,2,3',','); string_to_array - {1,2,3

Re: [SQL] Problem with transaction in functions and tempory tables

2004-07-22 Thread Stephan Szabo
On Thu, 22 Jul 2004, Gerardo Castillo wrote: > Hello, > > I'm using PostgreSQL 7.4 > > I have a function wich use temporary tables. I read about temporary tables > and they exists during the session. > But i have to call this function many times in the same sesion with > diferents parameters and e

Re: [SQL] LIKE on index not working

2004-07-22 Thread Tom Lane
"Chris Cox" <[EMAIL PROTECTED]> writes: > For some reason I just can't get this to use the index for the following > query. I'm using PostgreSQL 7.3.4. It works for me in 7.3.6 (see below). I'd guess that you are using a non-LIKE-safe locale setting --- can you get LIKE to use indexes at all? r

Re: [SQL] surrogate key or not?

2004-07-22 Thread Josh Berkus
Kasten, > I have until now used surrogate primary keys on all table like > so: > Short question: Is this OK re your concerns for using > surrogates, eg. using a surrogate but making sure that at any > one time there *would* be a real primary key candidate ? Yes, this is an example of that. Yo

[SQL] Problem with transaction in functions and tempory tables

2004-07-22 Thread Gerardo Castillo
Hello,   I'm using PostgreSQL 7.4   I have a function wich use temporary tables. I read about temporary tables and they exists during the session. But i have to call this function many times in the same sesion with diferents parameters and expecting different results. So, there is a problem

Re: [SQL] LIKE on index not working

2004-07-22 Thread Chris Browne
[EMAIL PROTECTED] ("Chris Cox") writes: > Hi all, > > For some reason I just can't get this to use the index for the following > query. I'm using PostgreSQL 7.3.4. > > Here's the details (let me know if you need anymore information to provide > any assistance): > > Indexes: person_pkey primary key

[SQL] Converting a plperlu function to a plpgsql function

2004-07-22 Thread Devin Whalen
Hello, I am trying to convert a database function that is written in perl to a PL/pgSQL function. However, there a a couple of lines that I don't think can be converted. First line: my @active_tables=split(/,/,$tables); Is there anyway to split a variable like the perl split above? Second lin

Re: [SQL] next integer in serial key

2004-07-22 Thread Stephan Szabo
On Thu, 22 Jul 2004 [EMAIL PROTECTED] wrote: > > > Alternatively, you can do: > > > INSERT (accepting the default) > > > then SELECT currval(the_sequence_object); > > > then > > > > > > NOTE: 2nd method assumes that nobody else called nextval() on the > > > sequence between when you did the > >

Re: [SQL] next integer in serial key

2004-07-22 Thread terry
That usually works. But if you can have 2 records in that table that are identical except the serial column, your query to get the id will return 2 results. Its also inefficient, if that query is costly (whether or not it can return 2 results). That's why I do: SELECT nextval(my_tables_sequen

Re: [SQL] next integer in serial key

2004-07-22 Thread Kenneth Gonsalves
On Thursday 22 July 2004 05:45 pm, Oliver Elphick wrote: > On Thu, 2004-07-22 at 12:48, [EMAIL PROTECTED] wrote: > > Actually it does work, call nextval to get your next value, then call > > your INSERT statement, > > explicitly giving said value for the serial column. Then you can > > proceed wit

Re: [SQL] next integer in serial key

2004-07-22 Thread Kenneth Gonsalves
On Thursday 22 July 2004 05:18 pm, [EMAIL PROTECTED] wrote: > Alternatively, you can do: > INSERT (accepting the default) > then SELECT currval(the_sequence_object); > then did this. barf: foreign key not in original table -- regards kg http://www.onlineindianhotels.net - hotel bookings reser

Re: [SQL] next integer in serial key

2004-07-22 Thread terry
> > Alternatively, you can do: > > INSERT (accepting the default) > > then SELECT currval(the_sequence_object); > > then > > > > NOTE: 2nd method assumes that nobody else called nextval() on the > > sequence between when you did the > > insert and when you did the select currval(). Note that > b

Re: [SQL] surrogate key or not?

2004-07-22 Thread Karsten Hilbert
Josh, I reckon you are the one in the know so I'll take advantage of that and ascertain myself of your advice. I am the primary designer for the database schema of GnuMed (www.gnumed.org) - a practice management application intended to store medical data. Obviously we wouldn't want ambigous data.

Re: [SQL] LIKE on index not working

2004-07-22 Thread Peter Eisentraut
Am Donnerstag, 22. Juli 2004 09:38 schrieb Chris Cox: > For some reason I just can't get this to use the index for the following > query. I'm using PostgreSQL 7.3.4. In 7.3, LIKE cannot use an index unless you set the locale to C. In 7.4, LIKE can use an index, but it has to be a different kind

Re: [SQL] next integer in serial key

2004-07-22 Thread Oliver Elphick
On Thu, 2004-07-22 at 12:48, [EMAIL PROTECTED] wrote: > Actually it does work, call nextval to get your next value, then call > your INSERT statement, > explicitly giving said value for the serial column. Then you can > proceed with using said value in > the INSERT statement of the related inserts

Re: [SQL] next integer in serial key

2004-07-22 Thread terry
Actually it does work, call nextval to get your next value, then call your INSERT statement, explicitly giving said value for the serial column. Then you can proceed with using said value in the INSERT statement of the related inserts with foreign keys to it. Alternatively, you can do: INSERT

Re: [SQL] connection delay

2004-07-22 Thread Achilleus Mantzios
O kyrios cristi egrapse stis Jul 22, 2004 : > I have a client made in java who interogate postgres using jdbc driver. > If the tcp conection falls (for a few seconds) the client give an error > message about that connection. > How can I avoid this error? If its not a jdbc issue, maybe you can pla

[SQL] connection delay

2004-07-22 Thread cristi
I have a client made in java who interogate postgres using jdbc driver. If the tcp conection falls (for a few seconds) the client give an error message about that connection. How can I avoid this error? ---(end of broadcast)--- TIP 4: Don't 'kill -9

[SQL] LIKE on index not working

2004-07-22 Thread Chris Cox
Hi all, For some reason I just can't get this to use the index for the following query. I'm using PostgreSQL 7.3.4. Here's the details (let me know if you need anymore information to provide any assistance): Indexes: person_pkey primary key btree (personid), ix_person_active btree (bac