Re: Simulating sequences

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Dustin Sallings <dustin(at)spy(dot)net>
Cc: btober(at)seaworthysys(dot)com, pgsql-general(at)postgresql(dot)org, paulo(dot)pizarro(at)digitro(dot)com(dot)br
Subject: Re: Simulating sequences
Date: 2003-08-19 17:12:26
Message-ID: 3F425A7A.5050004@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dustin Sallings wrote:

> On Monday, Aug 18, 2003, at 09:01 US/Pacific, <btober(at)seaworthysys(dot)com>
> wrote:
>
>> With those items in mind, your function could become:
>>
>> CREATE FUNCTION key_generation(integer, varchar(20)) RETURNS integer
>> AS'
>> DECLARE
>> the_department ALIAS FOR $1;
>> the_table_name ALIAS FOR $2;
>> BEGIN
>> IF NOT EXISTS(SELECT 1 FROM cnfg_key_generation
>> WHERE the_department = department AND the_table_name = table_name)
>> THEN
>> INSERT INTO cnfg_key_generation VALUES
>> (the_department,the_table_name,0);
>> END IF;
>
> I would get the insert out of there, too. If it doesn't exist, throw
> an exception. I don't believe sequences should automatically create
> themselves (the tables and columns don't).

Not in PostgreSQL or any other serious database. But given that MySQL
tries hard to never error out and mangles over the input in an even
destructive way by concept, you might have a fair chance to get a
misspelled column name in an INSERT statement interpreted as implicit
ALTER TABLE ...

Jan

>
> --
> SPY My girlfriend asked me which one I like better.
> pub 1024/3CAE01D5 1994/11/03 Dustin Sallings <dustin(at)spy(dot)net>
> | Key fingerprint = 87 02 57 08 02 D0 DA D6 C8 0F 3E 65 51 98 D8 BE
> L_______________________ I hope the answer won't upset her. ____________
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Roger Hand 2003-08-19 17:19:12 Re: 3 way outer join dilemma
Previous Message btober 2003-08-19 17:10:05 Re: Simulating sequences