Re: PL/pgSQL 1.2 - Mailing list pgsql-hackers

From Oskari Saarenmaa
Subject Re: PL/pgSQL 1.2
Date
Msg-id 540B4588.1060505@ohmu.fi
Whole thread Raw
In response to Re: PL/pgSQL 1.2  (Jan Wieck <jan@wi3ck.info>)
Responses Re: PL/pgSQL 1.2
List pgsql-hackers
06.09.2014 19:12, Jan Wieck kirjoitti:
> On 09/06/2014 04:21 AM, Marko Tiikkaja wrote:
>> We wrap these things into (sometimes) simple-looking function so that
>> none of the application developers ever run any SQL.  We define an
>> interface between the application and the database, and that interface
>> is implemented using PL/PgSQL functions.  Sure, sometimes one function
>> will just fire off a single UPDATE .. RETURNING, or a SELECT, but that
>> doesn't matter.  The trick is to be consistent everywhere.
>
> There is precisely your root problem. Instead of educating your
> application developers on how to properly use a relational database
> system, you try to make it foolproof.

There are also other reasons to wrap everything in functions, for 
example sharding using pl/proxy which by the way always throws an error 
if a SELECT didn't match exactly one row and the function wasn't 
declared returning 'SETOF' (although it currently doesn't set any 
sqlstate for these errors making it a bit difficult to properly catch them.)

Anyway, I think the discussed feature to make select, update and delete 
throw an error if they returned or modified <> 1 row would be more 
useful as an extension of the basic sql statements instead of a plpgsql 
(2) only feature to make it possible to use it from other languages and 
outside functions.

/ Oskari



pgsql-hackers by date:

Previous
From: Marko Tiikkaja
Date:
Subject: Re: proposal: plpgsql - Assert statement
Next
From: Marko Tiikkaja
Date:
Subject: Re: PL/pgSQL 1.2