Re:

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: Matthew Peter <survivedsushi(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re:
Date: 2006-01-10 10:02:17
Message-ID: 43C38629.6030508@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Matthew Peter wrote:
> CREATE OR REPLACE FUNCTION getlist(text) RETURNS SETOF my_tbl as $$
> SELECT * FROM my_tbl
> WHERE u_id IN (0, $1);
>
> $$ LANGUAGE SQL;
>
> SELECT * from getlist('1,2,3');
> (0 rows)

You're executing SELECT * FROM my_tbl WHERE u_id IN (0, '1,2,3').
Apparently there are no values 0 or '1,2,3' for u_id in that table.

> I'm sure it's probably trival but I'm still learning how psql :) Thanks

You can split the string into values with string_to_array(). You'll
still be comparing ints with strings though.

Without casting the resulting strings to ints you run the risk that the
database needs to cast the int u_id value to text for every record
encountered. For 'small' data sets this shouldn't be a problem.

I suppose this is a simplified example, or you wouldn't have a reason to
use an SP; you'd just SELECT * FROM my_tbl WHERE u_id IN (0,1,2,3)

--
Alban Hertroys
alban(at)magproductions(dot)nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

//Showing your Vision to the World//

In response to

  • Re: at 2006-01-09 23:26:45 from Matthew Peter

Browse pgsql-general by date

  From Date Subject
Next Message Robert Greimel 2006-01-10 11:43:16 Re: function overloading
Previous Message Nico Callewaert 2006-01-10 07:33:29 Best programming language / connectivity for best performance