I'm trying to do:
update nodes n1 set n1.parent_id=(s elect n2.id from
nodes n2 where n2.key=n1.paren t_id);
To set parent_id to the id of the parent (rather than
the key). Would UPDATE FROM fromlist work? I couldn't
find any examples of it's use.
TIA,
CSN
_______________ _______________ ____
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html
---------------------------(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 3 11705
On Fri, Feb 13, 2004 at 12:18:14AM -0800, CSN wrote: I'm trying to do: update nodes n1 set n1.parent_id=(s elect n2.id from nodes n2 where n2.key=n1.paren t_id); To set parent_id to the id of the parent (rather than the key). Would UPDATE FROM fromlist work? I couldn't find any examples of it's use.
See the online help:
# \h update
Command: UPDATE
Description: update rows of a table
Syntax:
UPDATE [ ONLY ] table SET col = expression [, ...]
[ FROM fromlist ]
[ WHERE condition ]
So try:
update nodes set parent_id=n2.id FROM nodes n2 where n2.key=nodes.pa rent_id;
Unfortunatly you can't alias the table you're updating, but you can alias
the rest.
--
Martijn van Oosterhout <kl*****@svana. org> http://svana.org/kleptog/ (... have gone from d-i being barely usable even by its developers anywhere, to being about 20% done. Sweet. And the last 80% usually takes 20% of the time, too, right?) -- Anthony Towns, debian-devel-announce
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQFALIqMY5T wig3Ge+YRAmPoAJ 49DzRhs6GoQa3b0 HWhIm6TvnnVqgCg mqKZ
VHnFrhGp4wXlAsa 1co1zNbI=
=B2FR
-----END PGP SIGNATURE-----
That does the trick. I'd also like to figure out a way
to set all parent_ids to NULL if no parent row can be
found. I haven't been able to figure it out so far.
Thanks,
CSN
--- Martijn van Oosterhout <kl*****@svana. org> wrote: On Fri, Feb 13, 2004 at 12:18:14AM -0800, CSN wrote: I'm trying to do:
update nodes n1 set n1.parent_id=(s elect n2.id from nodes n2 where n2.key=n1.paren t_id);
To set parent_id to the id of the parent (rather than the key). Would UPDATE FROM fromlist work? I couldn't find any examples of it's use.
See the online help:
# \h update Command: UPDATE Description: update rows of a table Syntax: UPDATE [ ONLY ] table SET col = expression [, ...] [ FROM fromlist ] [ WHERE condition ]
So try:
update nodes set parent_id=n2.id FROM nodes n2 where n2.key=nodes.pa rent_id;
Unfortunatly you can't alias the table you're updating, but you can alias the rest. -- Martijn van Oosterhout <kl*****@svana. org> http://svana.org/kleptog/ (... have gone from d-i being barely usable even by its developers anywhere, to being about 20% done. Sweet. And the last 80% usually takes 20% of the time, too, right?) -- Anthony Towns, debian-devel-announce
ATTACHMENT part 2 application/pgp-signature
_______________ _______________ ____
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html
---------------------------(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
On Fri, 13 Feb 2004, CSN wrote: That does the trick. I'd also like to figure out a way to set all parent_ids to NULL if no parent row can be found. I haven't been able to figure it out so far.
could a circular foreign key reference with one delete set null type thing
work? then it'd be automagic
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives? http://archives.postgresql.org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jim Moseby |
last post by:
I stumbled across this while trying to update a table with a timestamp type column. At the time, I didn't know that the timstamp column would update itself when a row was changed. A kind gentleman in another group pointed that out to me.
I added a column to a table and wanted to update the rows to populate the new column. When doing something like this I usually will create a temporary table and perform a dry run, just to make sure I am...
|
by: shottarum |
last post by:
I currently have 2 tables as follows:
CREATE TABLE .
(
mhan8 int,
mhac02 varchar(5),
mhmot varchar(5),
mhupmj int
)
|
by: andri.wardhana |
last post by:
Hi Guys,
I have a problem with my ASP file. since I'm all new in ASP, i found
that the error statement generated by ASP is confusing. basically what
I want to do in this script is ability to change password. Currently
this script's running well in the PHP version ( I rewrote the entire
PHP app to ASP app):
1. The form contains these fields : old password, new passwd, confirm
new passwd. users have to input old passwd in order to change...
|
by: FreeToGolfAndSki |
last post by:
Hi,
I have an Orders Table that has Employee1 and Employee2 (one is the
sales rep the other is the telemarketing rep) Both of these fields
need to cascade update against the Employees table. I can't seem to
create the desired relationship in a Diagram and I'm not sure how best
to set this up. Any ideas?
Thanks in advance...
|
by: polocar |
last post by:
Hi,
I'm writing a program in Visual C# 2005 Professional Edition.
This program connects to a SQL Server 2005 database called
"Generations" (in which there is only one table, called
"Generations"), and it allows the user to add, edit and delete the
various records of the table.
"Generations" table has the following fields:
"IDPerson", NamePerson", "AgePerson" and "IDParent".
A record contains the information about a person (his name, his...
| |
by: Roger |
last post by:
I am doing some mass update on DB2 8.2 FP10 (say 400 to 500 rows on a
5000 row table) with just one commit. So this is taking lot of
exclusive row locks as expected. When I run a select on the same
table with a where clause its taking a IS table lock. This is causing
the select to go on lock waiting.
The application cannot do UR isolation level. Why is it taking IS
table lock ? There is an index on the where clause. How can i...
|
by: DreamersDelight |
last post by:
Hi,
I'm stuck on this problem and I can't find a sollution. I'm going to try and explain this step by step.
1 After certain rows get updated with a certain value. I don't know wich rows in advance. And they do not have a certain order, but after the update they all have the same trans_id. (in unload_details_tab).
2 I select select the rows using the value that just got updated (trans_id), this way I know wich rows I needed to select, the...
|
by: abinesh.agarwal |
last post by:
Hi ,
I want to update the column in a table based on the updation of the
other column in the same table, but not getting the desired result.
DDL:
CREATE TABLE .(
NULL,
|
by: dlite922 |
last post by:
I have a permission table that gives a userID permission to a module and the any actions within that module.
What I want to do is duplicate his permissions to another user.
Permission table has:
id (PK)
userID (FK)
module
action
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |