{"id":1422,"date":"2013-06-28T09:25:36","date_gmt":"2013-06-28T16:25:36","guid":{"rendered":"http:\/\/blog.light42.com\/wordpress\/?p=1422"},"modified":"2013-09-28T09:26:20","modified_gmt":"2013-09-28T16:26:20","slug":"postgresql-banter-on-record-pseudotype","status":"publish","type":"post","link":"http:\/\/blog.light42.com\/wordpress\/?p=1422","title":{"rendered":"PostgreSQL banter on &#8216;record pseudotype&#8217;"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-575\" alt=\"PostgreSQL_logo.3colors.120x120\" src=\"http:\/\/blog.light42.com\/wordpress\/wp-content\/uploads\/2012\/06\/PostgreSQL_logo.3colors.120x120.png\" width=\"120\" height=\"120\" \/><br \/>\n<strong>dmg_83<\/strong> Okay. I notice that if you a table like <code>CREATE TABLE tbl (x int, y int)<\/code> and do <code>SELECT (tbl).x, (tbl).y FROM tbl WHERE tbl = ROW(1,2)<\/code> you&#8217;ll indeed get back 1, 2 (assuming such a row exists). That seems a bit weird, since the left side of the expression &#8220;tbl = ROW(1,2)&#8221; does not seem to be the same as the right, for we can do (tbl).x, but can&#8217;t do (ROW(1,2)).x; tbl contains some additional data that ROW(1,2) does not<\/p>\n<p><strong>dmg_83<\/strong> I&#8217;d like to understand the exact rules PG uses for these. I&#8217;m guessing it&#8217;s similar to something like how python compares a namedtuple and an ordinary tuple (disregarding the names and treating both as tuples for comparison sakes)<\/p>\n<p><strong>RhodiumToad<\/strong> row(1,2) actually uses column names &#8220;f1&#8221; and &#8220;f2&#8221; internally but that&#8217;s quite difficult to determine (and usually impossible to make use of)<br \/>\n&nbsp;&nbsp;you can&#8217;t do (row(1,2)).f1 for example<br \/>\n&nbsp;&nbsp;anyway, tbl = row(1,2) works because there&#8217;s a generic (record = record) operator defined<br \/>\n&nbsp;&nbsp;and any composite type can implicitly cast to the &#8220;record&#8221; pseudotype<br \/>\n&nbsp;&nbsp;the operator actually looks up the structure of the records at runtime (cached between calls from a single call site)<br \/>\n&nbsp;&nbsp;the number and types of fields has to be acceptable, but the column names are ignored<\/p>\n","protected":false},"excerpt":{"rendered":"<p>dmg_83 Okay. I notice that if you a table like CREATE TABLE tbl (x int, y int) and do SELECT (tbl).x, (tbl).y FROM tbl WHERE tbl = ROW(1,2) you&#8217;ll indeed get back 1, 2 (assuming such a row exists). That seems a bit weird, since the left side of the expression &#8220;tbl = ROW(1,2)&#8221; does [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1422"}],"collection":[{"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1422"}],"version-history":[{"count":1,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1422\/revisions"}],"predecessor-version":[{"id":1423,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1422\/revisions\/1423"}],"wp:attachment":[{"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1422"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}