Skip to content

Commit

Permalink
Merge #38869
Browse files Browse the repository at this point in the history
38869: sql: compatibility blitz for pgadmin r=jordanlewis a=jordanlewis

A bunch of small improvements to the catalog, new builtins, and a couple of typing improvements all in the name of making pgadmin work.

And it works okay now! Definitely still some flaws and unsupported things, but at least the default experience isn't completely broken anymore.

Closes #33341.
Closes #23299.
Closes #26389.
Closes #26378.
Closes #26390.
Closes #24747.
Closes #37124.
Updates #25213.

![image](https://user-images.githubusercontent.com/43821/61190353-f17fb980-a668-11e9-947f-d1bc3bb1e75d.png)

Co-authored-by: Jordan Lewis <[email protected]>
  • Loading branch information
craig[bot] and jordanlewis committed Jul 19, 2019
2 parents b011606 + 0180907 commit 7a6f5a9
Show file tree
Hide file tree
Showing 26 changed files with 688 additions and 267 deletions.
11 changes: 11 additions & 0 deletions docs/generated/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ has no relationship with the commit order of concurrent transactions.</p>
<table>
<thead><tr><th>Function &rarr; Returns</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>aclexplode(aclitems: <a href="string.html">string</a>[]) &rarr; tuple{oid AS grantor, oid AS grantee, string AS privilege_type, bool AS is_grantable}</code></td><td><span class="funcdesc"><p>Produces a virtual table containing aclitem stuff (returns no rows as this feature is unsupported in CockroachDB)</p>
</span></td></tr>
<tr><td><code>crdb_internal.unary_table() &rarr; tuple</code></td><td><span class="funcdesc"><p>Produces a virtual table containing a single row with no values.</p>
<p>This function is used only by CockroachDB’s developers for testing purposes.</p>
</span></td></tr>
Expand Down Expand Up @@ -997,6 +999,15 @@ SELECT * FROM crdb_internal.check_consistency(true, ‘\x02’, ‘\x04’)</p>
</span></td></tr></tbody>
</table>

### TUPLE functions

<table>
<thead><tr><th>Function &rarr; Returns</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>row_to_json(row: tuple) &rarr; jsonb</code></td><td><span class="funcdesc"><p>Returns the row as a JSON object.</p>
</span></td></tr></tbody>
</table>

### Compatibility functions

<table>
Expand Down
7 changes: 6 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/array
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,16 @@ DROP TABLE a

# Element append

# Postgres also requires that the string be explicitly casted, so we're no worse
# for wear despite this being a little annoying.
query T
SELECT ARRAY['a','b','c'] || 'd'
SELECT ARRAY['a','b','c'] || 'd'::text
----
{a,b,c,d}

query error unsupported binary operator
SELECT ARRAY['a','b','c'] || 'd'

query T
SELECT ARRAY[1,2,3] || 4
----
Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/grant_table
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ test pg_catalog pg_am public S
test pg_catalog pg_attrdef public SELECT
test pg_catalog pg_attribute public SELECT
test pg_catalog pg_auth_members public SELECT
test pg_catalog pg_cast public SELECT
test pg_catalog pg_class public SELECT
test pg_catalog pg_collation public SELECT
test pg_catalog pg_constraint public SELECT
test pg_catalog pg_conversion public SELECT
test pg_catalog pg_database public SELECT
test pg_catalog pg_default_acl public SELECT
test pg_catalog pg_depend public SELECT
test pg_catalog pg_description public SELECT
test pg_catalog pg_enum public SELECT
Expand All @@ -111,15 +114,20 @@ test pg_catalog pg_index public S
test pg_catalog pg_indexes public SELECT
test pg_catalog pg_inherits public SELECT
test pg_catalog pg_language public SELECT
test pg_catalog pg_locks public SELECT
test pg_catalog pg_matviews public SELECT
test pg_catalog pg_namespace public SELECT
test pg_catalog pg_operator public SELECT
test pg_catalog pg_prepared_xacts public SELECT
test pg_catalog pg_proc public SELECT
test pg_catalog pg_range public SELECT
test pg_catalog pg_rewrite public SELECT
test pg_catalog pg_roles public SELECT
test pg_catalog pg_seclabel public SELECT
test pg_catalog pg_seclabels public SELECT
test pg_catalog pg_sequence public SELECT
test pg_catalog pg_settings public SELECT
test pg_catalog pg_shdepend public SELECT
test pg_catalog pg_shdescription public SELECT
test pg_catalog pg_shseclabel public SELECT
test pg_catalog pg_stat_activity public SELECT
Expand Down
40 changes: 40 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ pg_catalog pg_am
pg_catalog pg_attrdef
pg_catalog pg_attribute
pg_catalog pg_auth_members
pg_catalog pg_cast
pg_catalog pg_class
pg_catalog pg_collation
pg_catalog pg_constraint
pg_catalog pg_conversion
pg_catalog pg_database
pg_catalog pg_default_acl
pg_catalog pg_depend
pg_catalog pg_description
pg_catalog pg_enum
Expand All @@ -287,15 +290,20 @@ pg_catalog pg_index
pg_catalog pg_indexes
pg_catalog pg_inherits
pg_catalog pg_language
pg_catalog pg_locks
pg_catalog pg_matviews
pg_catalog pg_namespace
pg_catalog pg_operator
pg_catalog pg_prepared_xacts
pg_catalog pg_proc
pg_catalog pg_range
pg_catalog pg_rewrite
pg_catalog pg_roles
pg_catalog pg_seclabel
pg_catalog pg_seclabels
pg_catalog pg_sequence
pg_catalog pg_settings
pg_catalog pg_shdepend
pg_catalog pg_shdescription
pg_catalog pg_shseclabel
pg_catalog pg_stat_activity
Expand Down Expand Up @@ -400,10 +408,13 @@ pg_am
pg_attrdef
pg_attribute
pg_auth_members
pg_cast
pg_class
pg_collation
pg_constraint
pg_conversion
pg_database
pg_default_acl
pg_depend
pg_description
pg_enum
Expand All @@ -415,15 +426,20 @@ pg_index
pg_indexes
pg_inherits
pg_language
pg_locks
pg_matviews
pg_namespace
pg_operator
pg_prepared_xacts
pg_proc
pg_range
pg_rewrite
pg_roles
pg_seclabel
pg_seclabels
pg_sequence
pg_settings
pg_shdepend
pg_shdescription
pg_shseclabel
pg_stat_activity
Expand Down Expand Up @@ -535,10 +551,13 @@ system pg_catalog pg_am SYSTEM VIE
system pg_catalog pg_attrdef SYSTEM VIEW NO 1
system pg_catalog pg_attribute SYSTEM VIEW NO 1
system pg_catalog pg_auth_members SYSTEM VIEW NO 1
system pg_catalog pg_cast SYSTEM VIEW NO 1
system pg_catalog pg_class SYSTEM VIEW NO 1
system pg_catalog pg_collation SYSTEM VIEW NO 1
system pg_catalog pg_constraint SYSTEM VIEW NO 1
system pg_catalog pg_conversion SYSTEM VIEW NO 1
system pg_catalog pg_database SYSTEM VIEW NO 1
system pg_catalog pg_default_acl SYSTEM VIEW NO 1
system pg_catalog pg_depend SYSTEM VIEW NO 1
system pg_catalog pg_description SYSTEM VIEW NO 1
system pg_catalog pg_enum SYSTEM VIEW NO 1
Expand All @@ -550,15 +569,20 @@ system pg_catalog pg_index SYSTEM VIE
system pg_catalog pg_indexes SYSTEM VIEW NO 1
system pg_catalog pg_inherits SYSTEM VIEW NO 1
system pg_catalog pg_language SYSTEM VIEW NO 1
system pg_catalog pg_locks SYSTEM VIEW NO 1
system pg_catalog pg_matviews SYSTEM VIEW NO 1
system pg_catalog pg_namespace SYSTEM VIEW NO 1
system pg_catalog pg_operator SYSTEM VIEW NO 1
system pg_catalog pg_prepared_xacts SYSTEM VIEW NO 1
system pg_catalog pg_proc SYSTEM VIEW NO 1
system pg_catalog pg_range SYSTEM VIEW NO 1
system pg_catalog pg_rewrite SYSTEM VIEW NO 1
system pg_catalog pg_roles SYSTEM VIEW NO 1
system pg_catalog pg_seclabel SYSTEM VIEW NO 1
system pg_catalog pg_seclabels SYSTEM VIEW NO 1
system pg_catalog pg_sequence SYSTEM VIEW NO 1
system pg_catalog pg_settings SYSTEM VIEW NO 1
system pg_catalog pg_shdepend SYSTEM VIEW NO 1
system pg_catalog pg_shdescription SYSTEM VIEW NO 1
system pg_catalog pg_shseclabel SYSTEM VIEW NO 1
system pg_catalog pg_stat_activity SYSTEM VIEW NO 1
Expand Down Expand Up @@ -1267,10 +1291,13 @@ NULL public system pg_catalog pg_am
NULL public system pg_catalog pg_attrdef SELECT NULL YES
NULL public system pg_catalog pg_attribute SELECT NULL YES
NULL public system pg_catalog pg_auth_members SELECT NULL YES
NULL public system pg_catalog pg_cast SELECT NULL YES
NULL public system pg_catalog pg_class SELECT NULL YES
NULL public system pg_catalog pg_collation SELECT NULL YES
NULL public system pg_catalog pg_constraint SELECT NULL YES
NULL public system pg_catalog pg_conversion SELECT NULL YES
NULL public system pg_catalog pg_database SELECT NULL YES
NULL public system pg_catalog pg_default_acl SELECT NULL YES
NULL public system pg_catalog pg_depend SELECT NULL YES
NULL public system pg_catalog pg_description SELECT NULL YES
NULL public system pg_catalog pg_enum SELECT NULL YES
Expand All @@ -1282,15 +1309,20 @@ NULL public system pg_catalog pg_index
NULL public system pg_catalog pg_indexes SELECT NULL YES
NULL public system pg_catalog pg_inherits SELECT NULL YES
NULL public system pg_catalog pg_language SELECT NULL YES
NULL public system pg_catalog pg_locks SELECT NULL YES
NULL public system pg_catalog pg_matviews SELECT NULL YES
NULL public system pg_catalog pg_namespace SELECT NULL YES
NULL public system pg_catalog pg_operator SELECT NULL YES
NULL public system pg_catalog pg_prepared_xacts SELECT NULL YES
NULL public system pg_catalog pg_proc SELECT NULL YES
NULL public system pg_catalog pg_range SELECT NULL YES
NULL public system pg_catalog pg_rewrite SELECT NULL YES
NULL public system pg_catalog pg_roles SELECT NULL YES
NULL public system pg_catalog pg_seclabel SELECT NULL YES
NULL public system pg_catalog pg_seclabels SELECT NULL YES
NULL public system pg_catalog pg_sequence SELECT NULL YES
NULL public system pg_catalog pg_settings SELECT NULL YES
NULL public system pg_catalog pg_shdepend SELECT NULL YES
NULL public system pg_catalog pg_shdescription SELECT NULL YES
NULL public system pg_catalog pg_shseclabel SELECT NULL YES
NULL public system pg_catalog pg_stat_activity SELECT NULL YES
Expand Down Expand Up @@ -1508,10 +1540,13 @@ NULL public system pg_catalog pg_am
NULL public system pg_catalog pg_attrdef SELECT NULL YES
NULL public system pg_catalog pg_attribute SELECT NULL YES
NULL public system pg_catalog pg_auth_members SELECT NULL YES
NULL public system pg_catalog pg_cast SELECT NULL YES
NULL public system pg_catalog pg_class SELECT NULL YES
NULL public system pg_catalog pg_collation SELECT NULL YES
NULL public system pg_catalog pg_constraint SELECT NULL YES
NULL public system pg_catalog pg_conversion SELECT NULL YES
NULL public system pg_catalog pg_database SELECT NULL YES
NULL public system pg_catalog pg_default_acl SELECT NULL YES
NULL public system pg_catalog pg_depend SELECT NULL YES
NULL public system pg_catalog pg_description SELECT NULL YES
NULL public system pg_catalog pg_enum SELECT NULL YES
Expand All @@ -1523,15 +1558,20 @@ NULL public system pg_catalog pg_index
NULL public system pg_catalog pg_indexes SELECT NULL YES
NULL public system pg_catalog pg_inherits SELECT NULL YES
NULL public system pg_catalog pg_language SELECT NULL YES
NULL public system pg_catalog pg_locks SELECT NULL YES
NULL public system pg_catalog pg_matviews SELECT NULL YES
NULL public system pg_catalog pg_namespace SELECT NULL YES
NULL public system pg_catalog pg_operator SELECT NULL YES
NULL public system pg_catalog pg_prepared_xacts SELECT NULL YES
NULL public system pg_catalog pg_proc SELECT NULL YES
NULL public system pg_catalog pg_range SELECT NULL YES
NULL public system pg_catalog pg_rewrite SELECT NULL YES
NULL public system pg_catalog pg_roles SELECT NULL YES
NULL public system pg_catalog pg_seclabel SELECT NULL YES
NULL public system pg_catalog pg_seclabels SELECT NULL YES
NULL public system pg_catalog pg_sequence SELECT NULL YES
NULL public system pg_catalog pg_settings SELECT NULL YES
NULL public system pg_catalog pg_shdepend SELECT NULL YES
NULL public system pg_catalog pg_shdescription SELECT NULL YES
NULL public system pg_catalog pg_shseclabel SELECT NULL YES
NULL public system pg_catalog pg_stat_activity SELECT NULL YES
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/join
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,6 @@ SELECT NULL::text AS pktable_cat,
AND con.oid = dep.objid
AND pkic.oid = dep.refobjid
AND pkic.relkind = 'i'
AND dep.classid = 'pg_constraint'::regclass::oid
AND dep.refclassid = 'pg_class'::regclass::oid
AND fkn.nspname = 'public'
AND fkc.relname = 'orders'
ORDER BY pkn.nspname,
Expand Down
21 changes: 21 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/json_builtins
Original file line number Diff line number Diff line change
Expand Up @@ -996,3 +996,24 @@ query I
SELECT jsonb_array_length('[]')
----
0

query TTT
SELECT row_to_json(row(1,'foo')), row_to_json(NULL), row_to_json(row())
----
{"f1": 1, "f2": "foo"} NULL {}


# TODO(jordan,radu): this should also work without the .*.
query T
select row_to_json(t.*)
from (
select 1 as a, 2 as b
) t
----
{"a": 1, "b": 2}

query T
SELECT '["a", {"b":1}]'::jsonb #- '{1,b}'
----
["a", {}]

Loading

0 comments on commit 7a6f5a9

Please sign in to comment.