473,602 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing from base type to inherited

Here's my issue:

Data comes in and is inserted into the database automatically, into a base
table A. Later a human looks at the records, fills in some data, and now the
records are assigned to some derived table, B or C. In some cases there is
no way for the software to know at import time which derived type the data
actually is (that determination requires someone to examine an image).

1) Is there any way to change a row of table A into one of the inherited
types, other than deleting and inserting?

2) If I must delete & insert, is there any shortcut to somehow say rec2.A =
rec1 rather than referencing the columns of the base table individually?

In other words, is there a more concise or elegant way to write the
following stored procedure? "Document" is the base table,
"EventMonitorRe port" is the derived table.

create or replace function
"EventMonitorRe port_Assign" (int8, int8, int8, int2, timestamp)
returns int8 as '
declare docid alias for $1; ptid alias for $2; drid alias for $3;
testnum alias for $4; testwhen alias for $5;
declare docrec record;
begin
select into docrec * from "Document" where id = docid;
if found then
delete from "Document" where id = docid;
insert into "EventMonitorRe port"
(id, "PatientId" , "OriginatedWhen ", "ReceivedWh en",
"CreatedWhe n", "CurVersFileId" , "Source", "Type", "Status",
"OurDrId", "TestNum", "TestedWhen ", "AssignedWh en")
values
(docid, ptid, docrec."Origina tedWhen", docrec."Receive dWhen",
docrec."Created When",
docrec."CurVers FileId", docrec."Source" , docrec."Type",
docrec."Status" ,
drid, testnum, testwhen, now());
end if;
return docrec.id;
end;
' language 'plpgsql';
--
Scott Ribe
sc********@kill erbytes.com
http://www.killerbytes.com/
(303) 665-7007 voice
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #1
2 1262
Scott Ribe <sc********@kil lerbytes.com> writes:
1) Is there any way to change a row of table A into one of the inherited
types, other than deleting and inserting?
Nope.
2) If I must delete & insert, is there any shortcut to somehow say rec2.A =
rec1 rather than referencing the columns of the base table individually?


Can't you do something like

INSERT INTO B SELECT *, some-more-values FROM A WHERE ...

regards, tom lane

---------------------------(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 23 '05 #2
> Can't you do something like

INSERT INTO B SELECT *, some-more-values FROM A WHERE ...


Yes, that works. I didn't think of trying that because I also need to check
for existence of A and change some values in it if it exists, so I select it
into a record type, and

insert into B docrec.*, some-more-values;

does not work.

Not using the record type, instead inserting into B as per your suggestion
and immediately updating B, is a lot less code, which was what I asked for.
And in this case there couldn't possibly be a material difference in
performance, so good enough.

Would it be a reasonable feature request to ask for the ability to use
myrecord.* on a record type as a value list?
--
Scott Ribe
sc********@kill erbytes.com
http://www.killerbytes.com/
(303) 665-7007 voice
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #3

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

Similar topics

1
4332
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an inherited base member's access level in the derived class: its access level in the base class and the type of inheritance (public, protected, or private). After this determination is made, the following possibilities exist for manually changing the...
7
5752
by: Santi | last post by:
I have two classes: Product and Fruit which inherits from Product. If I try to narrow the reference to the base type by a cast, I always get a reference to the inherited type. For example: Fruit lemon = new Fruit(); Product prod = (Product)lemon; // Now prod is a Fruit Type!! I want to get a Product reference from a Fruit object, is it possible? thank you.
4
2842
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. '**************************************************************************** ' Issues '****************************************************************************
2
2140
by: Walt Zydhek | last post by:
Could someone tell me how to Change the parameter type for an override of an inherited class member? In particular, I would like to change an indexer for my class that implements the IList class. Such as this: public abstract class myclass : IList { private ArrayList ary; .... public string this
13
2832
by: dragoncoder | last post by:
Consider the following code #include <iostream> class Base { public: virtual void say() { std::cout << "Base" << std::endl; } }; class Derived: public base {
5
3601
by: Eliseu Rodrigues | last post by:
Hi I would like to have a static method on a base class that executes some action (for example retrieves the row count) on a table whose name is the same of the inherited class name. For example: Assume that my base class has a static method named GetRowCount().
4
3296
by: Tugrul HELVACI | last post by:
Changing DisplayNames of my properties using PropertyGrid component, how ?? I'm using Delphi 2006 and I have a class defination like this: TPerson = class fPersonName : String; fPersonSurName : String; fPersonAge : Integer; published property PersonName : String read fPersonName write fPersonName;
19
2221
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit modify come of the classes so they match our purpose better - mostly add a few methods etc. Example: Open source lib has classes Map and Layer defined. The relationship between them is one to many. We created our own versions (inherited) of Map...
12
2157
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I have a class which "BiologySequence" which looks about like this. public class BiologySequence { private string _Sequence; public string Sequence {
0
7993
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
7920
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
8401
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...
0
8404
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...
0
8268
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
5440
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();...
1
2418
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
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
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.