473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

plpgsql , dynamic queries

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

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #1
1 3991
It would be easier to help you with the quoting issues if you provided
an example of the entire query you need to execute and/or the code
you're using to build the query.

Quoting in a function can get pretty hairy sometimes. You might find
this chart helpful, I certainly have:

http://www.postgresql.org/docs/7.3/s...l-porting.html (see
"19.11.1.1. Quote Me on That: Escaping Single Quotes")

I suspect this chart shouldn't be hidden in the "Porting from Oracle
PL/SQL" section of the docs.

-heath
On Wednesday, August 27, 2003, at 08:40 PM, Alex wrote:
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 ?

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rajesh Kumar Mallah | last post by:
Hi, profile_row profile_master%ROWTYPE; in a plpgsql function gives the error below tradein_clients=# SELECT general.create_accounts(); WARNING: plpgsql: ERROR during compile of...
1
by: Alex | last post by:
Hi, i have a problem with quoting in plpgsql. I try to insert dynamically some conditions into a select statment but for some reason it does not work. condition := '' AND price > 500 ''; ...
7
by: Ford Desperado | last post by:
there is an application which issues a lot of simple dynamic queries against an Oracle database. If CURSOR_SHARING is set to FORCE, Oracle treats dynamic queries as static ones, for instance...
6
by: bill.postgresql-users | last post by:
What's the best way to ease development of plpgsql. My largest issues with plpgsql pertain to the quoting of course. Bill McMilleon ---------------------------(end of...
4
by: Bill Moran | last post by:
I've got a bit of a strange problem that's causing me some MAJOR headaches. I'm developing the server-side of a large database application in PostgreSQL. This consists of a C daemon, and a LOT...
2
by: Igor Shevchenko | last post by:
Hi. I've got a problem with using cursor in a plpgsql function. Cursor is created via DECLARE, it's SELECT query has placeholders. I use PostgreSQL 7.4.2. Here's a problematic plpgsql...
2
by: David Boone | last post by:
I've been trying to create functions with postgres, but it seems that queries run within a function take wayyy too long to complete. The increased time seems to be in the actual queries, not...
0
by: sripathy sena | last post by:
Hi, I am trying to install OPenacs with postgres 7.4.3 as the database. The openacs requires plpgsql to be installed. When I try to do this by running "CREATELANG plpgsql template1". I get a...
1
by: vituko | last post by:
plpgsql (postgresql 8.3 but I can upgrade) I can open a cursor with a dynamic query (table / column variable) : -open cursor for execute '...' ; But if I want do updates... - execute 'update...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.