PostgreSQL 17.12Lab-verified · 2026-12-01

PostgreSQL error 0A000: feature not supported

The statement uses something PostgreSQL does not support. The message text tells you which feature.

PostgreSQL 17.12
0A000: cannot alter type of a column used by a view or rule

Jump to a cause

  1. 01ALTER COLUMN TYPE on a column that a view uses
  2. 02Referencing another database with database.schema.table
  3. 03FOR UPDATE on a query with count() or other aggregates
  4. 04A subquery inside a CHECK constraint (to allow only code-table values)

Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-12-01 · container image postgres:17

0A000 is a shared SQLSTATE for "not supported". The message after the code is what matters: cannot alter type of a column used by a view or rule, cross-database references are not implemented, FOR UPDATE is not allowed with aggregate functions and so on. Each needs a different fix, so search for the message, not only the code.

01ALTER COLUMN TYPE on a column that a view uses

Widening products.name from varchar(20) to varchar(100) fails because the view product_list selects that column. The DETAIL line names the view: rule _RETURN on view product_list depends on column "name". Other views may depend on it too; the pg_depend query lists every view that uses the table.

Setup
Setuprun as lab_a
CREATE TABLE products (id int PRIMARY KEY, name varchar(20), price int);
INSERT INTO products VALUES (1, 'pen', 100);
CREATE VIEW product_list AS SELECT id, name, price FROM products;
OUTPUT
CREATE TABLE
INSERT 0 1
CREATE VIEW
Reproducerun as lab_a
ALTER TABLE products ALTER COLUMN name TYPE varchar(100);
✕ ERROR
ERROR:  0A000: cannot alter type of a column used by a view or rule
DETAIL:  rule _RETURN on view product_list depends on column "name"
Checkrun as lab_a
SELECT DISTINCT v.relname AS view_name FROM pg_depend d JOIN pg_rewrite r ON r.oid = d.objid JOIN pg_class v ON v.oid = r.ev_class WHERE d.refobjid = 'products'::regclass AND v.relname <> 'products';
OUTPUT
  view_name
--------------
 product_list
(1 row)

In one transaction, drop the view, change the column type and create the view again. If anything fails, the whole transaction rolls back, so the view is never left missing. Save the view definitions (and any grants on them) before you drop them.

After the fixrun as lab_a
BEGIN;
DROP VIEW product_list;
ALTER TABLE products ALTER COLUMN name TYPE varchar(100);
CREATE VIEW product_list AS SELECT id, name, price FROM products;
COMMIT;
SELECT * FROM product_list;
✓ SUCCESS
BEGIN
DROP VIEW
ALTER TABLE
CREATE VIEW
COMMIT
 id | name | price
----+------+-------
  1 | pen  |   100
(1 row)

02Referencing another database with database.schema.table

PostgreSQL cannot query a table in another database from the same connection, so otherdb.public.orders fails. This happens often when SQL written for SQL Server or MySQL is moved to PostgreSQL. current_database() shows you are connected to lab.

Setup
Setuprun as lab_a
CREATE TABLE orders (id int PRIMARY KEY);
OUTPUT
CREATE TABLE
Reproducerun as lab_a
SELECT * FROM otherdb.public.orders;
✕ ERROR
ERROR:  0A000: cross-database references are not implemented: "otherdb.public.orders"
LINE 1: SELECT * FROM otherdb.public.orders;
                      ^
Checkrun as lab_a
SELECT current_database(), current_schema();
OUTPUT
 current_database | current_schema
------------------+----------------
 lab              | lab_a
(1 row)

If the table is in the same database, use only schema.table (here lab_a.orders). If it really is in another database, you need to connect to that database or use an extension such as postgres_fdw or dblink — that part was not run here.

After the fixrun as lab_a
SELECT * FROM lab_a.orders;
✓ SUCCESS
 id
----
(0 rows)

03FOR UPDATE on a query with count() or other aggregates

SELECT count(*) … FOR UPDATE fails because the aggregated result is not a table row that can be locked. You usually wanted to lock the rows and count them.

Setup
Setuprun as lab_a
CREATE TABLE jobs (id int PRIMARY KEY, status text);
INSERT INTO jobs VALUES (1, 'ready'), (2, 'ready'), (3, 'done');
OUTPUT
CREATE TABLE
INSERT 0 3
Reproducerun as lab_a
SELECT count(*) FROM jobs WHERE status = 'ready' FOR UPDATE;
✕ ERROR
ERROR:  0A000: FOR UPDATE is not allowed with aggregate functions
Checkrun as lab_a
SELECT id FROM jobs WHERE status = 'ready' ORDER BY id FOR UPDATE;
OUTPUT
 id
----
  1
  2
(2 rows)

Lock the rows in a subquery and count outside: SELECT count(*) FROM (SELECT id FROM jobs WHERE status = 'ready' FOR UPDATE) AS locked. It returns 2, the same rows that the plain SELECT id … FOR UPDATE returns.

After the fixrun as lab_a
SELECT count(*) FROM (SELECT id FROM jobs WHERE status = 'ready' FOR UPDATE) AS locked;
✓ SUCCESS
 count
-------
     2
(1 row)

04A subquery inside a CHECK constraint (to allow only code-table values)

To allow only values from a code table, CHECK (status IN (SELECT code FROM status_codes)) was used. A CHECK can only look at the row's own values, so it fails with cannot use subquery in check constraint.

Setup
Setuprun as lab_a
CREATE TABLE status_codes (code text PRIMARY KEY);
INSERT INTO status_codes VALUES ('NEW'), ('PAID');
OUTPUT
CREATE TABLE
INSERT 0 2
Reproducerun as lab_a
CREATE TABLE orders (
  id     int PRIMARY KEY,
  status text CHECK (status IN (SELECT code FROM status_codes))
);
✕ ERROR
ERROR:  0A000: cannot use subquery in check constraint
LINE 3:   status text CHECK (status IN (SELECT code FROM status_code...
                                    ^
Checkrun as lab_a
SELECT code FROM status_codes ORDER BY code;
OUTPUT
 code
------
 NEW
 PAID
(2 rows)

Limiting values to another table is a job for a foreign key. With status text REFERENCES status_codes (code), the table was created and 'PAID' was inserted.

After the fixrun as lab_a
CREATE TABLE orders (
  id     int PRIMARY KEY,
  status text REFERENCES status_codes (code)
);
INSERT INTO orders VALUES (1, 'PAID');
SELECT * FROM orders;
✓ SUCCESS
CREATE TABLE
INSERT 0 1
 id | status
----+--------
  1 | PAID
(1 row)

FAQ

How do I alter a column type used by a view in PostgreSQL?

Drop the view, run ALTER TABLE … ALTER COLUMN … TYPE, then create the view again, all inside one BEGIN … COMMIT. Check pg_depend first for every view that depends on the table.

What does cross-database references are not implemented mean?

You wrote database.schema.table. PostgreSQL can only query tables in the database you are connected to. Use schema.table, or connect to the other database.

Why is FOR UPDATE not allowed with aggregate functions?

Aggregate results are not rows that can be locked. Put FOR UPDATE in a subquery that selects the rows, and aggregate outside it.

What is SQLSTATE 0A000?

feature_not_supported. Many different messages share it, so read the message text to see which feature is not supported.

How do I fix cannot use subquery in check constraint?

A CHECK cannot query other tables. To allow only values from a code table, use a foreign key with REFERENCES.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12