See the original question and code further down. Here is the code that works:
SELECT v1.s_owner_guid,
n.node_name as s_owner_name
FROM vm_list v
CROSS JOIN LATERAL (
SELECT (VALUES (TRIM(split_part(v2.set_of_guids, ':', 3), '|')))
) v1(s_owner_guid)
LEFT JOIN nodes n
ON n.id = v1.s_owner_guid::uuid
Original code that does not work:
SELECT
(TRIM (split_part(v2.set_of_guids, ':', 3)), '|') AS s_owner_guid
, n1.node_name as s_owner_name
FROM vm_list as v2
INNER JOIN nodes
AS n1
ON n1.id=s_owner_guid
I want to get s_owner_guid and s_owner_name out of this SELECT
This is a part of the query that I am having issues with and is a nested SELECT
The error I get is:
ERROR: column "s_owner_guid" does not exist
LINE 7: ON v2.owner=s_owner_guid
I have a set_of_guids containing 2 node uids seperated by certain characters
I have 2 tables with the information I need
vm_list
and nodes are the 2 tablesvm_owner_guid
is a column in vm_list table that has the uid matching id column in nodes tableid
is a column in the nodes tablevm_name
is a column in vm_list with the VM namenode_name
is a column in nodes with that is associated with the id column in nodes table- the first uid in the set_of_guids matches the vm_owner and also the id column in the nodes table and has a node_name in another column in nodes
I need to parse the set_of_nodes to get the second uid for the VM so I am using the SPLIT_PART and TRIM options to isolate the uid and am calling it s_owner_guid
I need to take s_owner_guid and match it against id in the nodes table to get the second node_name
Ultimately the output will look something like this:
vm_name | p_owner_guid | p_owner_name | s_owner_guid | s_owner_name
-------------+---------------------------------------+-------------------+---------------------------------------+-----------------------
NAMEOFVM1 | b2a0bb4e-0a6a-4208-8ff1-6df549cf9c3f | primary_node_name | 1c732242-56d4-c9c8-d275-ba271600c314 | secondary_node_name
I can get the first 4 fields now, but not the last s_owner_name. Is there any way to accomplish this? I am trying not to create a temporary table due to having a live system depending on the DB.