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

shortcut for select * where id in (arrayvar)

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: <pgsql-general(at)postgresql(dot)org>
Subject: shortcut for select * where id in (arrayvar)
Date: 2008-03-30 21:56:01
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
I'm still investigating on how to return array elements.

I came out with something like:

create or replace function auz(out _errcode int, out _errmsg text)
returns setof record as $$
	errcode int[];
	errmsg text[];
	_row record;
	errmsg[1]:='pota pota';
	errmsg[2]:='bau bau';
	for i IN coalesce(array_lower(errcode,1),0) ..
 		loop _errcode:=errcode[i];
		_errmsg:=errmsg[i]; return next;
	end loop;
$$ language plpgsql;

I'd like to avoid to hard code error messages in the function so I
was thinking about adding a table with error_id, error_messages and
change the for loop with something similar to

for _row in
	select err, msg from errortable where err in (errcode)

where errcode is an array.
That syntax doesn't work... is there any alternative syntax to keep
stuff short and not error prone?

I could serialise the array and build up the string of the
where err in (......)
but it doesn't make things look that better.


Ivan Sergio Borgonovo


pgsql-general by date

Next:From: Joris DobbelsteenDate: 2008-03-30 21:59:36
Subject: Re: database 1.2G, pg_dump 73M?!
Previous:From: Ross BoylanDate: 2008-03-30 21:43:26
Subject: Re: database 1.2G, pg_dump 73M?!

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