postgresql , how can i add to my query a list of values to the where clause ?

hello experts,

i'm looking on how to add a list of values at the end of my query in order to
receive the answer only for a group of values.

i'm looking to add somegthing like the last line,
except that my values are not comming from a subquery.

  CD.rf_card_id = TB.rf_card_id
  CD.account_id = AC.account_id
  TB.container_id = TB.container_id
  AND account_id in (101, 102, 103, 104, 110)    <-

thank you in advance.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

earth man2Connect With a Mentor Commented:
somewhere  you need to build the account_id string as a comma seperated list then append it to the string buffer for your query.

sinply ...
  String acids = "101, 102, 103, 104, 110";

 sb.Append( " AND AC.account_id in ("  );
 sb.Append( acids );
  sb.Append( " )" );

  sb.Append(" ORDER BY ASC; ");
Edit the statement
If this is prepared statement - pass array of strings as parameter in place.
toshi_Author Commented:
hello gheist,
could you be more explicit please,

i'm not an expert, neither with postgresql nor with english ;o)

what i would need is to view how to write the list,
i'll correcte the string generation after what is correct.

thank you for further help.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

It is not PostgreSQL problem.

How do you pass statement to PostgreSQL?
Where does it come from?
toshi_Author Commented:
i pass my query from .NET c# to
postgresql 8.4 through Npgsql,

     //sb.Append(" TB.weight*0.5 as GEWICHT, ") ;
            sb.Append(" CASE WHEN  ") ;
                sb.Append(" TB.weight*0.5 >= 0.5 AND ") ;
                sb.Append(" TB.weight*0.5 <= 5.0 ") ;
                    sb.Append(" THEN 5.0 ") ;
                sb.Append(" ELSE TB.weight*0.5 ") ;
            sb.Append(" END AS GEWICHT, ") ;

            sb.Append(" 0 as FNFLAG,");
            sb.Append(" CD.rf_card_id  as RFCID, ");    
            sb.Append(" AC.account_id as ACCID ");
            sb.Append(" FROM ");
            sb.Append(" trash_bag as TB, rf_card as CD, account as AC ");
            sb.Append(" WHERE ");
            sb.Append(" CD.rf_card_id = TB.rf_card_id ");
            sb.Append(" AND ");
            sb.Append(" CD.account_id = AC.account_id ");
            sb.Append(" AND ");
            sb.Append(" TB.container_id = TB.container_id ");

// i want to reduce the query by passing a list of containers.

            // TIME
            // sb.Append(" AND > '2008-01-01' ");
            //sb.Append(" AND > '" + aBegin.ToString(PgsSymbolicConstant.DATE_FORMAT_DB)+  "'");
            sb.Append(" AND > '" + aBegin.ToString(PgsSymbolicConstant.DATETIME_FORMAT_DB)+  "'");
            // sb.Append(" AND < '2008-01-31' ");
            //sb.Append(" AND <= '" + _theEnd.ToString(PgsSymbolicConstant.DATE_FORMAT_DB)+  "'");
            sb.Append(" AND <= '" + _theEnd.ToString(PgsSymbolicConstant.DATETIME_FORMAT_DB)+  "'");
            sb.Append(" ORDER BY date ASC; ");

            DataTable _dtForExport = dba_.ExecuteQuery(sb.ToString());

            //DataTable _dtFiltered= FilterZerosAndMinimal(_dtForExport);

            return _dtForExport;
I have asked moderators to add .net area(s), there is nothing specific to PostgreSQL in your .NET program
toshi_Author Commented:
i'd like to know how to set a list of values to restrict my query,
is a question of query,
it doesnt nothing have to do with .NET
i think i 'm not accurate enough with english language

but there's someting I'M SURE "this is a postresql question"

All Courses

From novice to tech pro — start learning today.