FDW question - how to identify columns to populate in response? - Mailing list pgsql-hackers

From Bear Giles
Subject FDW question - how to identify columns to populate in response?
Date
Msg-id CALBNtw4DJE9oka-pSy148wHc1Y-yz+=n7qsPGWkhO2Jyj4K09A@mail.gmail.com
Whole thread Raw
Responses Re: FDW question - how to identify columns to populate in response?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;color:#000000">Hi, I'm working on a FDW
forthe unix/linux user database - think /etc/passwd and /etc/group although I'm actually using system calls that could
bequietly redirected to LDAP or other backends. It's easy to create the FDW and a table associated with it, something
like</div><divclass="gmail_default" style="font-family:tahoma,sans-serif;color:#000000"><br /></div><div
class="gmail_default"style="font-family:tahoma,sans-serif;color:#000000">CREATE TABLE passwd (</div><div
class="gmail_default"style="font-family:tahoma,sans-serif;color:#000000">   name text,</div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000">  passwd text,</div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000">  uid int,</div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000">  ...</div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000"><br/></div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000">Theproblem is the user could decide to reorder or remove columns so
Ican't make the assumption that values[0] is always going to be the username.</div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000"><br/></div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000">Ihave a solution that requires looking at the rel, extracting the
atts,and then doing a loop where I check the attname against all possible values for each column. Anything that doesn't
matchis set to null. This isn't too bad here but it would be a pain if there are many columns.</div><div
class="gmail_default"style="font-family:tahoma,sans-serif;color:#000000"><br /></div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000">Isthere a cleaner way? I've looked at a number of other FDW
implementationsbut they are generally mapping columns to columns (so it's a short bit of lookup code inside the loop),
notcopying data provided by a system call.</div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000"><br/></div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000">Thanks,</div><divclass="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000"><br/></div><div class="gmail_default"
style="font-family:tahoma,sans-serif;color:#000000">Bear</div></div>

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: why can the isolation tester handle only one waiting process?
Next
From: Tom Lane
Date:
Subject: Re: FDW question - how to identify columns to populate in response?