472,374 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

function with tablename parameter

hello,

it is possible to write something similar???

create function get_count(varchar(32)) RETURNS int4 AS '
DECLARE
tmp int4;
BEGIN
SELECT COUNT(*) INTO tmp FROM $1;
RETURN tmp;
END;' LANGUAGE 'plpgsql';
SELECT get_count('k_part');
SQL error:
ERROR: parser: parse error at or near "$1" at character 24

thanx, miso
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #1
2 4884
On Mon, 27 Oct 2003, Miso Hlavac wrote:
hello,

it is possible to write something similar???

create function get_count(varchar(32)) RETURNS int4 AS '
DECLARE
tmp int4;
BEGIN
SELECT COUNT(*) INTO tmp FROM $1;
RETURN tmp;
END;' LANGUAGE 'plpgsql';


Youll need to do something a little more complicated like:

create function get_count(varchar) RETURNS int8 AS '
DECLARE
tmp record;
BEGIN
FOR tmp IN EXECUTE ''SELECT COUNT(*) AS count FROM '' || $1 LOOP
RETURN tmp.count;
END LOOP;
END;'
LANGUAGE 'plpgsql';
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #2

To use dynamic queries you will probably have to use EXECUTE, take a look
here

http://www.postgresql.org/docs/7.3/i...nts.html#PLPGS
QL-STATEMENTS-EXECUTING-DYN-QUERIES

Although that page says that EXECUTE does not support SELECT INTO queries,
but you may be able to build something using FOR-IN-EXECUTE as described in
this section:

http://www.postgresql.org/docs/7.3/i...-structures.ht
ml#PLPGSQL-RECORDS-ITERATING

HTH

Adam
hello,

it is possible to write something similar???

create function get_count(varchar(32)) RETURNS int4 AS '
DECLARE
tmp int4;
BEGIN
SELECT COUNT(*) INTO tmp FROM $1;
RETURN tmp;
END;' LANGUAGE 'plpgsql';
SELECT get_count('k_part');
SQL error:
ERROR: parser: parse error at or near "$1" at character 24

thanx, miso
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #3

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

Similar topics

2
by: SAN CAZIANO | last post by:
can you help me please because I can't understand why the code doesn't seems to function very well: in onkeypress it must verify if insert number or string value in the fiels, but it doesn't...
1
by: N E | last post by:
hello I am trying to do a procedure that : 1 - Take a table name, a field name and a value as parameter 2 - check if the fieldname=value in the tablename table 3 - returns 1 if so, 0 if not ...
2
by: Erik Grob \(MCP\) | last post by:
Does anyone know where to find or how to write a quick user defined fucntion that will return a table object when passed the string name of the table object. The reason why I want dynamicallly set...
3
by: David Link | last post by:
Hi All, Here's a Conditional drop_table func for those interested. There was a thread on this a long time back. We do this all the time : DELETE TABLE sales; CREATE TABLE sales (...);
1
by: Kruno Milicevic | last post by:
I want to fill DataGrid with some table from my database. I usual use something like this: string sqlString ="SELECT * FROM TableName"; OleDbCommand myOleDbCommand = new OleDbCommand(sqlString ,...
2
by: Lee Harr | last post by:
I am following along with the pl/pgsql docs here: http://www.postgresql.org/docs/current/static/plpgsql-declarations.html In section 37.4.3. Row Types I have altered the function slightly (I...
1
by: satish | last post by:
Hi, How do I run dynamic sql statements in side a UDF? Is there any work around to retrieve data that way? Example: -- Table create table dataTbl (col1 varchar(5),col2...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
1
by: bassi.carlo | last post by:
I have an application with many combobox in different forms used for choose a particular length (for example items are "ft" - feet, "in" - inch, "m" - meters, and so on). I don't want to put in...
14
by: gggram2000 | last post by:
Can anyone tell me if this class will function properly...I'm using MS Visual Studio 2005, using C#. I notice there's no C# forum but hopefully u guys are familiar with the language...thanks in...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.