Thread: Wrapper to use correct version of psql?

Wrapper to use correct version of psql?

From
Steve Atkins
Date:
I have a bunch of different version of postgresql installed, from 7.0
on forward, on various servers. As psql is fairly version specific,
and tends to misbehave if the client and server versions don't match,
I usually need to remember which version is running on which machine
and port.

The obvious thing to do is write a wrapper that will transparently run
the right version of psql for the database it's connecting to. Has
anyone already done that?

Cheers,
   Steve


how to remove the duplicate elements from an array?

From
Yi Zhao
Date:
hi all:
if I create an array '{44,55,66,c4,55,66,b4,55,66}',
how to remove the duplicate elements(55, 66) from it, after remove, the
array will be
'{44,55,66,c4,b4}'

thanks.


Re: how to remove the duplicate elements from an array?

From
"Pavel Stehule"
Date:
hello

try

create function uniq(anyarray)
returns anyarray as $$
select array(select distinct $1[i] from
generate_series(array_lower($1,1), array_upper($1,1)) g(i));
$$ language sql strict immutable;

postgres=# select uniq(array[1,2,3,1,2,3,5,2,2]);
   uniq
-----------
 {1,2,3,5}
(1 row)

regards
Pavel Stehule

2008/7/26 Yi Zhao <yi.zhao@alibaba-inc.com>:
> hi all:
> if I create an array '{44,55,66,c4,55,66,b4,55,66}',
> how to remove the duplicate elements(55, 66) from it, after remove, the
> array will be
> '{44,55,66,c4,b4}'
>
> thanks.
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

Re: how to remove the duplicate elements from an array?

From
Yi Zhao
Date:
yes, it's work.
thank u very much!

Regards
Yi
On Sat, 2008-07-26 at 21:37 +0200, Pavel Stehule wrote:
> hello
>
> try
>
> create function uniq(anyarray)
> returns anyarray as $$
> select array(select distinct $1[i] from
> generate_series(array_lower($1,1), array_upper($1,1)) g(i));
> $$ language sql strict immutable;
>
> postgres=# select uniq(array[1,2,3,1,2,3,5,2,2]);
>    uniq
> -----------
>  {1,2,3,5}
> (1 row)
>
> regards
> Pavel Stehule
>
> 2008/7/26 Yi Zhao <yi.zhao@alibaba-inc.com>:
> > hi all:
> > if I create an array '{44,55,66,c4,55,66,b4,55,66}',
> > how to remove the duplicate elements(55, 66) from it, after remove, the
> > array will be
> > '{44,55,66,c4,b4}'
> >
> > thanks.
> >
> >
> > --
> > Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-general
> >
>


Re: Wrapper to use correct version of psql?

From
Greg Smith
Date:
On Sat, 26 Jul 2008, Steve Atkins wrote:

> The obvious thing to do is write a wrapper that will transparently run the
> right version of psql for the database it's connecting to. Has anyone already
> done that?

Several times, and I never seem to have the previous rev around when
writing a new one (writing useful error checks is the time consuming
part).  The archives to my rescue:  the attached is something I just
whipped together which hopefully will be the last time I do this from
scratch again 'cause I can just find this post instead.  This presumes
you've installed all the versions into a directory tree at
/opt/pgsql/<version>, and you have to tweak the end of the script to make
it run that command instead of just printing the output.

Sample session using the script:

$ cat systems
aaa     hosta   5432    8.2
bbb     hostb   5432    8.3
$ ./runpsql aaa
/opt/pgsql/8.2/bin/psql -h hosta -p 5432
$ ./runpsql bbb
/opt/pgsql/8.3/bin/psql -h hostb -p 5432
$ ./runpsql ccc
system "ccc" not found in systems listing file at: systems

It appends the stuff after the system name to the psql command, but you do
have to worry about shell escaping with this simple implementation;
example:

$ ./runpsql bbb -Atc \"select 1\"
/opt/pgsql/8.3/bin/psql -h hostb -p 5432 -Atc "select 1"

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

Attachment