Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/functions/regtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ var regtypein = framework.Function1{
if typeName == "char" && schema == "" {
return id.NewType("pg_catalog", "bpchar").AsId(), nil
}
if typeName == "int" {
typeName = "int4"
}
if internalID, ok := pgtypes.NameToInternalID[typeName]; ok && (internalID.SchemaName() == schema || schema == "") {
return internalID.AsId(), nil
}
Expand Down
3 changes: 2 additions & 1 deletion server/functions/setval.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func parseRelationName(ctx *sql.Context, name string) (schema string, relation s
return "", "", errors.Errorf(`cannot parse relation: %s`, name)
}

// Trim any quotes from the relation name
// Trim any quotes from the schema and the relation name
schema = strings.Trim(schema, `"`)
relation = strings.Trim(relation, `"`)

return schema, relation, nil
Expand Down
72 changes: 72 additions & 0 deletions server/tables/information_schema/constraint_column_usage_view.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2026 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package information_schema

import (
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/information_schema"

"github.com/dolthub/doltgresql/server/functions"
)

// ConstraintColumnUsageViewName is the name of the CONSTRAINT_COLUMN_USAGE view.
const ConstraintColumnUsageViewName = "constraint_column_usage"

// newConstraintColumnUsageView creates a new information_schema.CONSTRAINT_COLUMN_USAGE view.
func newConstraintColumnUsageView() *information_schema.InformationSchemaTable {
return &information_schema.InformationSchemaTable{
TableName: ConstraintColumnUsageViewName,
TableSchema: constraintColumnUsageSchema,
Reader: constraintColumnUsageRowIter,
}
}

// constraintColumnUsage is the schema for the information_schema.CONSTRAINT_COLUMN_USAGE view.
var constraintColumnUsageSchema = sql.Schema{
{Name: "table_catalog", Type: sql_identifier, Default: nil, Nullable: true, Source: ConstraintColumnUsageViewName},
{Name: "table_schema", Type: sql_identifier, Default: nil, Nullable: true, Source: ConstraintColumnUsageViewName},
{Name: "table_name", Type: sql_identifier, Default: nil, Nullable: true, Source: ConstraintColumnUsageViewName},
{Name: "column_name", Type: character_data, Default: nil, Nullable: true, Source: ConstraintColumnUsageViewName},
{Name: "constraint_catalog", Type: character_data, Default: nil, Nullable: true, Source: ConstraintColumnUsageViewName},
{Name: "constraint_schema", Type: yes_or_no, Default: nil, Nullable: true, Source: ConstraintColumnUsageViewName},
{Name: "constraint_name", Type: yes_or_no, Default: nil, Nullable: true, Source: ConstraintColumnUsageViewName},
}

// constraintColumnUsageRowIter implements the sql.RowIter for the information_schema.CONSTRAINT_COLUMN_USAGE view.
func constraintColumnUsageRowIter(ctx *sql.Context, catalog sql.Catalog) (sql.RowIter, error) {
var rows []sql.Row

err := functions.IterateCurrentDatabase(ctx, functions.Callbacks{
Check: func(ctx *sql.Context, schema functions.ItemSchema, table functions.ItemTable, check functions.ItemCheck) (cont bool, err error) {

// TODO: Fill out the rest of the columns.
rows = append(rows, sql.Row{
schema.Item.Name(), // table_catalog
schema.Item.SchemaName(), // table_schema
table.Item.Name(), // table_name
nil, // column_name
nil, // constraint_catalog
nil, // constraint_schema
check.Item.Name, // constraint_name
})
return true, nil
},
})
if err != nil {
return nil, err
}

return sql.RowsToRowIter(rows...), nil
}
6 changes: 6 additions & 0 deletions server/tables/information_schema/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package information_schema

import (
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/information_schema"
)

Expand All @@ -25,4 +26,9 @@ func Init() {
information_schema.NewSchemataTable = newSchemataTable
information_schema.NewTablesTable = newTablesTable
information_schema.NewViewsTable = newViewsTable

// Postgres-specific tables/views to be added to information_schema database
information_schema.NewInformationSchemaTablesToAdd = map[string]sql.Table{
ConstraintColumnUsageViewName: newConstraintColumnUsageView(),
}
}
11 changes: 11 additions & 0 deletions testing/go/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,12 @@ func TestFunctionsOID(t *testing.T) {
{"integer"},
},
},
{
Query: `SELECT to_regtype(('int'::regtype)::text);`,
Expected: []sql.Row{
{"integer"},
},
},
{
Query: `SELECT to_regtype((('integer'::regtype)::oid)::text);`,
Expected: []sql.Row{
Expand Down Expand Up @@ -1393,6 +1399,11 @@ func TestSystemInformationFunctions(t *testing.T) {
ExpectedColNames: []string{"pg_get_serial_sequence"},
Expected: []sql.Row{{"public.t1_id_seq"}},
},
{
Query: `SELECT pg_get_serial_sequence('"public"."t1"', 'id');`,
ExpectedColNames: []string{"pg_get_serial_sequence"},
Expected: []sql.Row{{"public.t1_id_seq"}},
},
{
// Test with no schema specified
Query: `SELECT pg_get_serial_sequence('t1', 'id');`,
Expand Down
33 changes: 33 additions & 0 deletions testing/go/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,36 @@ func TestDiscard(t *testing.T) {
},
})
}

func TestRollback(t *testing.T) {
RunScripts(t, []ScriptTest{
{
Name: "Test rollback transaction",
SetUpScript: []string{
`BEGIN`,
`CREATE temporary TABLE test (a INT)`,
`insert into test values (1)`,
},
Assertions: []ScriptTestAssertion{
{
Query: "select * from test",
Expected: []sql.Row{{1}},
},
{
Query: "ROLLBACK",
Expected: []sql.Row{},
},
{
Query: "select * from test",
ExpectedErr: "table not found",
Skip: true, // temp table should be dropped after ROLLBACK
},
{
Query: "create temp table test (b int)",
Expected: []sql.Row{},
Skip: true, // temp table should be dropped after ROLLBACK
},
},
},
})
}