Skip site navigation (1) Skip section navigation (2)

proof concept: do statement parametrization

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: proof concept: do statement parametrization
Date: 2010-07-04 06:41:35
Message-ID: AANLkTilueazLDBUjEoxzILJZCwnMd1oLvap_1HugKIYQ@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Hello

I enhanced DO statement syntax to allowing a parameters. Syntax is
relative simple:

do ([varname] vartype := value, ...) $$ ... $$

It allows to pass a content of psql variables to inline code block to
allows more easy scripting

\set schema 'public'

do(text := :'schema') $$
declare r record;
begin
  for r in
      select * from information_schema.tables where table_schema = $1
  loop
    raise notice '>>> table %', r.table_name;
  end loop;
end $$;
NOTICE:  >>> table t
NOTICE:  >>> table t1
DO

ToDo:

* doesn't allows SubLinks :(

pavel(at)postgres:5432=# do(text := (SELECT :'schema')) $$ declare r
record; begin for r in select * from information_schema.tables where
table_schema = $1 loop raise notice '>>> table %', r.table_name; end
loop; end $$;
ERROR:  XX000: unrecognized node type: 315
LOCATION:  ExecInitExpr, execQual.c:4868

ideas, notes, comments??

Regards

Pavel Stehule

Attachment: do_parametrization.diff
Description: text/x-patch (16.2 KB)

Responses

pgsql-hackers by date

Next:From: Rainer PruyDate: 2010-07-04 07:40:06
Subject: Re: pessimal trivial-update performance
Previous:From: Robert HaasDate: 2010-07-04 04:17:32
Subject: Re: pessimal trivial-update performance

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group