proposal: doc: simplify examples of dynamic SQL - Mailing list pgsql-hackers

From Pavel Stehule
Subject proposal: doc: simplify examples of dynamic SQL
Date
Msg-id CAFj8pRA58o3fD23ruWDjuTQaF=iKukgJvkBosmfMgebOTnm2wA@mail.gmail.com
Whole thread Raw
Responses Re: proposal: doc: simplify examples of dynamic SQL
List pgsql-hackers
Hi

There are few less readable examples of dynamic SQL in plpgsql doc

like:

EXECUTE 'SELECT count(*) FROM '
    || tabname::regclass
    || ' WHERE inserted_by = $1 AND inserted <= $2'
   INTO c
   USING checked_user, checked_date;

or

EXECUTE 'UPDATE tbl SET '
        || quote_ident(colname)
        || ' = $'
        || newvalue
        || '$ WHERE key = '
        || quote_literal(keyvalue);

We can show a examples based on "format" function only:

EXECUTE format('SELECT count(*) FROM %I'
               ' WHERE inserted_by = $1 AND inserted <= $2',
            tabname)
   INTO c
   USING checked_user, checked_date;

or

EXECUTE format('UPDATE tbl SET %I = newvalue WHERE key = %L',
                    colname, keyvalue)
or

EXECUTE format('UPDATE tbl SET %I = newvalue WHERE key = $1',
                    colname)
  USING keyvalue;

A old examples are very instructive, but little bit less readable and maybe too complex for beginners.

Opinions?

Regards

Pavel

pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: pgcrypto: PGP signatures
Next
From: Marko Tiikkaja
Date:
Subject: Re: pgcrypto: PGP signatures