473,729 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get field value when field name is in variable

4 New Member
I have one view with 3 fields like the view name is myview and it has following sql statement.

Expand|Select|Wrap|Line Numbers
  1. select fn,ln,city from tablea
I created a function like below:-

Expand|Select|Wrap|Line Numbers
  1. create function myfun(in t myview, in f varchar(50)) returns varchar(100) as
Now i want to pass row and name of field and let it return the value from function on basis of field name i pass to the function like

Expand|Select|Wrap|Line Numbers
  1. select myfun(*, 'fn') from myview
this suppose to return value of fn from myfun because i'm passing fn as a parameter name.

hope it is clear, if yes, how i can achieve this?
May 14 '10 #1
5 9720
rski
700 Recognized Expert Contributor
You can use dynamic SQL. See here for EXECUTE command

http://www.postgresql.org/docs/curre...tatements.html
May 14 '10 #2
parry2k
4 New Member
No execute command didn't worked for me. this is what i did?

execute 't.' || quote_ident(f) into v;

in this case t and f are two parameters of function (as mentioned in question) and i declare v as a variable to get the value, it is not working

but if i do this

v := t.fn;

i get the value...so not sure how to get the value dynamically.
May 14 '10 #3
rski
700 Recognized Expert Contributor
where is select in that query
execute 't.' || quote_ident(f) into v;
Shouldn't there be somehting like that

Expand|Select|Wrap|Line Numbers
  1. execute 'select '||f||' from '|| t into v;
  2.  
Or I do not understand your problem.
May 14 '10 #4
parry2k
4 New Member
Thanks for quick report but it is not a table where I can use select so it didn't worked. Even if I try

Expand|Select|Wrap|Line Numbers
  1. select fn into v from t 
Without execute, it doesn't work. I think you didn't get my question.
May 14 '10 #5
parry2k
4 New Member
here is the link to an example and i'm trying to follow this

http://www.postgresql.org/docs/8.1/s...larations.html

Expand|Select|Wrap|Line Numbers
  1. CREATE FUNCTION concat_selected_fields(in_t sometablename) RETURNS text AS $$
  2. BEGIN
  3.     RETURN in_t.f1 || in_t.f3 || in_t.f5 || in_t.f7;
  4. END;
  5. $$ LANGUAGE plpgsql;'
in my case , field name is dynamic
May 14 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1904
by: kaston3 | last post by:
var totalpoints=0; for (counter=1;....){ myvalue=parseFloat(document.forms.elements.value); totalpoints+=myvalue //the fields in elements are always numbers }
1
8878
by: Stu | last post by:
Hi, I am trying to return the data key field value from a dataset when I select a row in a datagrid after the datagrid has been bound to a dataset. When I an the Edit, Update and Cancel row I can return the DataKey using the sub listed below. However, the select button does not have 'DataGridCommandEventArgs' as one of it's parameters so I cannot use the same command.
1
2574
by: Wayne Wengert | last post by:
I want to use the contents of one field to be the text the user clicks on for a hyperlink in a datagrid. I am trying the following code but it does not work. What is the correct syntax for this? The field "InfoURL" contains the hyperlink and the field "City" is a string field containing the text I want the user to be able to clock on. <columns> <asp:BoundColumn HeaderText="Start Date" DataField="StartDate" DataFormatString="{0:d}" />...
6
2103
by: JohnnyW | last post by:
Hello, I have I simple question that is not clear for me. So, I have a input field (text field) in my html page. User should give input as a string like following 12 345 678,0 If user gives input in format 12345678,0 and leves the input field how can I format the value 12345678,0 into format 12 345 678,0? Are there any Javascript that can handle this with Regular Expressions?
2
19608
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the field in table2. What I have is a form that is linked to Table2. If the users want to change a field in the main database (table1), they fill the change in to the form (which is linked to table2) If there is no change to the field, they simply...
5
14291
by: devx777 | last post by:
Hello, I am trying to find some information or an example on how to build a dynamic query in DB2 that would allow me to join a table which its name is stored as a field value on another table. I have done this in the past in SQL server, but DB2 is not as easy... Anyone out there that can help me? Your help will be much appreciated.
2
1562
by: dharmadam_man | last post by:
I want to use MERGE to UPDATE the rows when there is a match. If there is no match, I want to INSERT the rows, and at the same time change a column value to a constant. For example, change the PURGE_INDICATOR to 'Y' to all inserted rows. Is there an elegant way to achieve this?
7
2986
by: jmar | last post by:
I'm hoping someone out there can give me a little guidance. I have an Access Database "Customer.MDB" with a table "CustInfo" that has the following design: Field: DataType CustID AutoNumber Name Text Title Text Phone Text
1
1542
by: cbayr249 | last post by:
I'm currently making a database for a research project and I keep running into a problem. I have one master form with the tab control and several subforms. Each subform is backed by a table that are all connected by a single field "Accession Number". As I switch between subforms, I would like the subform to show a record with the same Accession Number as the previous subform. If that does not exist, to show a blank record with the previous...
8
13668
by: xtremebass | last post by:
Hi Bytes.. i have need to assign Mysql Database DataField value to shell script variable . is it possible ? i have tried like this .. got error.. #!bin/sh password=xxx mysql -u root -p$password -h 192.168.1.8 << y use dbssys; d ="`select mem from profile` ";
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9200
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
9142
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...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
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
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.