From: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> |
---|---|
To: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: proposal: doc: simplify examples of dynamic SQL |
Date: | 2014-10-03 03:16:07 |
Message-ID: | 542E14F7.5000601@BlueTreble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 10/2/14, 6:51 AM, Pavel Stehule wrote:
> EXECUTE format('UPDATE tbl SET %I = newvalue WHERE key = %L',
> colname, keyvalue)
> or
-1, because of quoting issues
> EXECUTE format('UPDATE tbl SET %I = newvalue WHERE key = $1',
> colname)
> USING keyvalue;
Better, but I think it should really be quote_ident( colname )
> A old examples are very instructive, but little bit less readable and maybe too complex for beginners.
>
> Opinions?
Honestly, I'm not to fond of either. format() is a heck of a lot nicer than a forest of ||'s, but I think it still falls short of what we'd really want here which is some kind of variable substitution or even a templating language. IE:
EXECUTE 'UDPATE tbl SET $colname = newvalue WHERE key = $keyvalue';
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2014-10-03 03:17:23 | Re: TAP test breakage on MacOS X |
Previous Message | Jim Nasby | 2014-10-03 03:07:36 | Re: DDL Damage Assessment |