473,780 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(tablena me) 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 1918
de*@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgr av?=) 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=F8rgr av?=) 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 YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #3
de*@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgr av?=) writes:
Tom Lane <tg*@sss.pgh.pa .us> writes:
de*@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgr av?=) 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 misunderstandin g. 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(tablena me) 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
11869
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 run time I am able to know the table on which i have to work. So I have created a Ref Cursor
0
2017
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 the ability to destroy the database (with all the other tables) just to get rid of this. Does anyone know of a way to get the database to allow a drop of a table that has this sort of situation. Here's a sample of what I get... Any thoughts...
2
1746
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 possiblities do I have to find it out? -> "find tablename where sys_obid=81653 ....?"
1
11339
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 , OleDbConn); OleDbDataAdapter myOleDbDataAdapter = new OleDbDataAdapter(); myOleDbDataAdapter.SelectCommand=myOleDbCommand; DataSet myDataSet=new DataSet(); myOleDbDataAdapter.Fill(myDataSet); DataGrid1.DataSource = myDataSet;
4
6466
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 JDBC. Assume we have a table named "test". Under PSQL, we can input "\d test" to see the details about table "test" successufully. However, my main purpose is trying to get column name, column name of a table through JDBC.
3
2661
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 rs As Recordset Dim ssql As String Set rs = CurrentDb("SELECT * FROM Merge;")
4
5015
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 of the datasetname. For example, if I have: private void simpleDataSetXml() { DataSet ds = new DataSet(); DataTable table = new DataTable("foo"); DataColumn col = new DataColumn("bar", System.Type.GetType("System.String"));...
2
16897
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 (Databases, tables, SPs, and so on) are displayed in the tree, table colums definitions in the list and I want to display the selected table content in the DataGridView. So far so good. Currently, I succedded in loading the treeview and the...
2
2748
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 the specified database, and columns/ fields in the specified table. Is there an SQL equivalent for use in
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.