New answers tagged


The problem arises because the aliases defined in the SELECT list are not visible by the same level WHERE clause - and the reason behind this is the order of logical execution of queries (which is roughly FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY, omitting some other clauses). You can bypass this problem with several methods: ...


If this is Mysql, instead of "+" use concat().So the line will be SET @Where = concat(@Where , 'CLASS LIKE \%' , @SearchText);


According to me you can write case for name. you can also use and operator with age in if clause, but that would be longer process if names are more.


Problem You had to pick the spot where all possible complications come together. SQL (or PL/pgSQL) does not allow to parameterize identifiers. You need dynamic SQL with EXECUTE for that. But the special plpgsql variable NEW in trigger functions is not visible inside dynamic code executed with EXECUTE. And it's further complicated by passing column names ...


In Postgres 8.4 or later you would use the USING clause of EXECUTE to pass values safely and efficiently. That's not available in your version 8.3, yet. In your version it could could work like this: CREATE OR REPLACE FUNCTION test_conditions() RETURNS SETOF bigint AS $func$ DECLARE _rec record; _func text; _result bigint; BEGIN FOR _func ...

Top 50 recent answers are included