plpgsql , dynamic queries

From: Alex <alex(at)meerkatsoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: plpgsql , dynamic queries
Date: 2003-08-28 00:40:00
Message-ID: 3F4D4F60.1090406@meerkatsoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I am having problems in forming a dynamic query that can be used in
Execute statements.

Problem:
I have database fields that are either INT or VARCHAR. Both can have NULL.

If I use variables that hold the db field's values ... how do I need to
quote them to pass them to the query string.

example:

_var1 := NULL;
_var2 := ''NULL'';

or
queryStr := ''WHERE name NOTNULL";
queryStr := ''WHERE name ='' || _var2/1

_var3 := ''somename'';
quereyStr := ''SET name='' || _var3;

I tried combinations but ending up with using 4 or 6 single quotes. Is
there an easy way to form such query strings ?

Any help would be appreciated.

Thanks

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alex 2003-08-28 00:46:08 plpgsql FOUND Variable
Previous Message Maksim Likharev 2003-08-28 00:13:27 Re: postgresql not using index even though it's faster