473,382 Members | 1,390 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,382 software developers and data experts.

tablename type?

The PL/PGSQL documentation contains at least two examples of functions
which take an argument of type "tablename", which then serves as a
table name in a query. Here's one of those examples:
CREATE FUNCTION concat_selected_fields(tablename) RETURNS text AS '
DECLARE
in_t ALIAS FOR $1;
BEGIN
RETURN in_t.f1 || in_t.f3 || in_t.f5 || in_t.f7;
END;
' LANGUAGE plpgsql;


Typing this at the psql prompt, however, simply results in the
following message:

ERROR: type tablename does not exist

Is the documentation incorrect, or is there something wrong with my
PostgreSQL 7.4.3 installation?

If the documentation is incorrect, is there another way to achieve
this, or do I have to use a varchar argument and construct and execute
a dynamic command?

DES
--
Dag-Erling Smørgrav - de*@des.no

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
3 1900
de*@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) writes:
Typing this at the psql prompt, however, simply results in the
following message: ERROR: type tablename does not exist


The example is just an example. Create an actual table and use its
name.

regards, tom lane

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

Nov 23 '05 #2
Tom Lane <tg*@sss.pgh.pa.us> writes:
de*@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) writes:
ERROR: type tablename does not exist

The example is just an example. Create an actual table and use its
name.


If you read the example, you will see that the function is clearly
intended to operate on a table whose name is specified as a parameter
to the function, and that "tablename" is used as the type name for
that parameter, and not a placeholder for an actual table name.

DES
--
Dag-Erling Smørgrav - de*@des.no

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #3
de*@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) writes:
Tom Lane <tg*@sss.pgh.pa.us> writes:
de*@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) writes:
ERROR: type tablename does not exist The example is just an example. Create an actual table and use its
name.

If you read the example, you will see that the function is clearly
intended to operate on a table whose name is specified as a parameter
to the function, and that "tablename" is used as the type name for
that parameter, and not a placeholder for an actual table name.


No, it's you who are misunderstanding. The example is showing use of a
composite-type parameter (ie, a row value). Perhaps fleshing out the
example will make it clearer:

regression=# create table tablename(f1 text, f3 text, f5 text, f7 text);
CREATE TABLE
regression=# insert into tablename values('a','b','c','d');
INSERT 577890 1
regression=# CREATE FUNCTION concat_selected_fields(tablename) RETURNS text AS '
regression'# DECLARE
regression'# in_t ALIAS FOR $1;
regression'# BEGIN
regression'# RETURN in_t.f1 || in_t.f3 || in_t.f5 || in_t.f7;
regression'# END;
regression'# ' LANGUAGE plpgsql;
CREATE FUNCTION
regression=# select * from tablename t;
f1 | f3 | f5 | f7
----+----+----+----
a | b | c | d
(1 row)

regression=# select concat_selected_fields(t.*) from tablename t;
concat_selected_fields
------------------------
abcd
(1 row)

regards, tom lane

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

http://archives.postgresql.org

Nov 23 '05 #4

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

Similar topics

1
by: Sri | last post by:
how to handle a situation where i wnt a variable of type ref cursor. TYPE refCur IS REF CURSOR; rc refCur; myRow rc%rowtype; -- How can I make this work??? The whole problem is that only on...
0
by: Liam3 | last post by:
I'm having a problem with a table that accidently had a column added whose type is the same as the table. This is seriously creating a problem as I cannot delete the table and I really don't have...
2
by: Christian Höhener | last post by:
Hi I have a given attributvalue of a specific attribut (sys_obid=81653) which occurs in multiple tables. Now, I should know the tablename of the table in which this attribut occurs. Which...
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 ,...
4
by: Ying Lu | last post by:
Hello, Under mysql, we have "desc tablename" to get the detail information about a table. My question is about to get column name, and column type for a specific table under PostgreSQL through...
3
by: JF | last post by:
I would like to automate a Union query going through the tables of my dataset using VBA: I have this code: ------------------------------------------------------------------- Sub ssql() Dim...
4
by: nautiboy | last post by:
This seems like it should be so trivial, but try as I might I can't figure it out. I want to write out a dataset as xml (i.e., DataSet.WriteXml()) but use the tablename as the root element instead...
2
by: Adrien Reboisson | last post by:
I'm trying to build a basic DB explorer using C# & Visual Studio 2005. I installed SQL Server 2005 Express, created a blank project, dropped a TreeView, a ListView and a DataGridView : DB objects...
2
by: Dan | last post by:
Hello, all! New here, so please forgive if this has been answered before. I use MySQL most often, and can use the commands: show tables in ; show columns in ; which lists all the tables in...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.