Skip to main content
Neki is currently in Platform Preview. Platform Preview features are “Beta Features” under the PlanetScale Terms of Service or your applicable agreement with PlanetScale. Accordingly, Neki is subject to the limitations and disclaimers applicable to Beta Features and is not covered by any service level agreement.
When Neki’s router cannot plan or execute a statement because an implementation is still missing, it returns SQLSTATE NK013 and a message in this form:
The bracketed number is a stable catalog code. It identifies one specific implementation gap, and it keeps that meaning for the life of the product: a code is never reused for a different gap, even after the gap is closed. Quote it when you report a rejected query, and use it to match a rejection your application sees against the entry below. NK013 means the gap is one Neki intends to close. A limit that is a design decision rather than a missing implementation is reported as not supported instead, and the broad ones are listed in Platform preview limitations. For how other Neki errors use the DETAIL and HINT fields, see Error hints and details.

How to read an entry

Each entry gives the code, the message sentence the router renders after the bracketed code, an example that triggers it, and a note on which part of the query causes the rejection. The examples use the example schema. A few entries name another small table whose own name describes the property that matters to that code. Where a rejection depends on how the data topology places the tables rather than on the SQL text, the note says so — the same statement can plan successfully with a different topology. Codes that only an internal invariant can raise are not listed, because no query produces them. A code absent from this page is one an application is unlikely to meet. A single statement can be rejected by more than one of these codes. Which one you see is the first gap the planner reaches, so fixing one can reveal another.

Statements, transactions, and sessions

Codes raised while the router decides what a statement is and how the session should behave.

1 — SELECT INTO statements are unavailable.

The INTO clause is what Neki rejects. At the top level Postgres treats SELECT ... INTO as CREATE TABLE AS; write that form instead.

20 — This statement type is unavailable.

The fallback for a statement no plan builder handles and for which the DDL surface has no more specific decision. A statement that the surface does recognize reports its own code instead.

21 — Reading an inheritance parent without ONLY is unavailable.

The rejection only occurs when inheritance_parent has child tables. Reading the parent without ONLY would have to expand to the children, so add ONLY to read just the parent.

23 — This transaction command is unavailable.

Raised for a transaction-control command the router has no handler for. BEGIN, COMMIT, ROLLBACK, SAVEPOINT, RELEASE SAVEPOINT, and ROLLBACK TO SAVEPOINT succeed. PREPARE TRANSACTION, COMMIT PREPARED, and ROLLBACK PREPARED return this code.

28 — SET FROM CURRENT is unavailable.

The FROM CURRENT form is rejected; give the parameter an explicit value.

29 — SET TRANSACTION SNAPSHOT is available only on a session that targets one shard.

Importing another session’s snapshot would have to be coordinated across every shard, so the statement is available only on a session that targets one shard.

30 — This statement cannot be analyzed with EXPLAIN neki_plan.

EXPLAIN (NEKI_PLAN, ANALYZE) runs the statement to show its router plan, and some statement types, such as CREATE TABLE AS, have none to show. The statement itself may still be supported when run directly.

31 — Data-modifying CTEs cannot be analyzed with EXPLAIN neki_plan.

The data-modifying CTE is the rejected part: EXPLAIN (NEKI_PLAN, ANALYZE) does not run a statement whose CTE writes.

32 — This EXPLAIN option is unavailable.

GENERIC_PLAN is one of the PostgreSQL EXPLAIN options the NEKI_PLAN renderer does not honor; the message names the option. Drop it, or run the EXPLAIN without NEKI_PLAN.

518 — This configuration parameter value is unavailable.

The parameter accepts only some of its PostgreSQL values on Neki; the error’s DETAIL names them.

537 — A WITH HOLD cursor whose router-computed part evaluates a function, operator or cast that is not IMMUTABLE is unavailable.

PostgreSQL computes the remaining rows of a held cursor at COMMIT. The router computes part of this query itself, here the aggregate across shards and now(), at each later FETCH, so a function that is not IMMUTABLE would answer for the FETCH and not for the commit. Declare the cursor without WITH HOLD, or compute the value in the client.

563 — Changing DateStyle, TimeZone, IntervalStyle, extra_float_digits, or client_encoding while a cursor over a router-computed query holds rows is unavailable.

The router encodes a cursor’s rows under the output settings in force at its first read, so it cannot honor a FETCH after one of them changes. Change the setting before the first FETCH.

660 — A cursor over this query shape is unavailable.

The join on name crosses shards, so the router computes it, and a row-locking cursor over a query the router computes is refused: a row mark would lock every row a shard returns, not only the rows you fetch. The message names the shape. Join on the shard key so the cursor runs on one shard, or lock the rows with a separate SELECT ... FOR UPDATE.

692 — Read-write multi-shard transactions at … are unavailable: atomic commit requires READ COMMITTED.

The first statement reached shard-meta, and the second would enroll a second shard. Atomic commit supports only READ COMMITTED, so the transaction cannot reach more than one shard at this isolation level. Run it at the default isolation level, or use multi mode.

817 — Planning against … is unavailable: earlier DDL in this transaction is not reflected in the router’s schema view.

The router plans against its own view of the schema, which DDL earlier in the same transaction has not reached yet. Commit the DDL first.

Topology and evaluation context

Codes that depend on how the data topology is configured, or on the context the router is evaluating in.

10 — Multi-column partitioning indexes are unavailable.

devices is sharded on owner_id + device_no, an expression over two columns, and INSERT ... VALUES cannot route on it. A columns list with more than one entry is rejected when the topology is applied; an expression over one column, such as lower(email), routes.

11 — This shard index cannot route advisory locks.

The topology names user_data as the advisory-lock shard group, and user_data routes on a modulo shard index. Neki hashes advisory-lock keys with xxhash, so a multi-shard advisory-lock group must use an xxhash default shard index, as the Example schema’s does.

41 — File COPY is unavailable for sharded tables.

Client COPY TO STDOUT works for sharded tables, reference tables, and materialized views, including text, CSV, and binary. The codes in this section are for file COPY.
File-based COPY against a sharded table. Use COPY ... FROM STDIN for a sharded table, or an unsharded table for file COPY.

43 — File COPY is unavailable for reference tables.

File-based COPY into a reference table. Use COPY ... FROM STDIN instead.

44 — COPY FROM cannot maintain this table’s secondary index.

Depends on the topology: the rejection occurs because the target table owns an active global secondary index, whose lookup rows COPY FROM cannot maintain. Load the table with INSERT instead.

45 — COPY does not support a multi-column primary shard index.

COPY FROM routes each row on a single-column shard key, and devices is sharded on an expression over two columns.

46 — COPY FROM cannot evaluate this reference-table default consistently.

The omitted column’s default is volatile, and a reference table stores the same logical row in several shard groups, so each copy could receive a different value. Supply the column explicitly.

47 — COPY TO PROGRAM is unavailable.

The TO PROGRAM destination is rejected; it would run a command on a Postgres host.

49 — COPY of a SELECT result is unavailable.

The parenthesized SELECT source is what is rejected. Copy a table, or run the query and handle the rows in your application.

50 — COPY FROM with a WHERE clause is unavailable.

The WHERE clause on COPY FROM is rejected. Filter the data before feeding it to COPY.

51 — COPY FROM cannot evaluate this column default on the router.

The column list omits created_at, whose default now() the router would have to evaluate per row. Include the column and supply its values.

52 — This COPY option is unavailable for sharded COPY.

Depends on the topology: for a sharded target, COPY options such as ON_ERROR, REJECT_LIMIT, and LOG_VERBOSITY are rejected. The same option is accepted for an unsharded table.

53 — This input encoding is unavailable for sharded COPY.

The router frames the rows of a sharded COPY stream byte by byte, which is unsafe for an encoding such as SJIS, whose multi-byte characters can contain a backslash byte. Send UTF-8.

54 — COPY is unavailable in a multi-statement query.

COPY must be the only statement in the query. The second statement in the batch is what makes this fail.

55 — COPY is unavailable in the extended query protocol.

Reachable only over the extended query protocol — that is, when the client prepares and binds the statement. The same COPY works over the simple query protocol.

350 — Notify channel routing requires an xxhash shard index.

As code 11, for notify_shard_group: Neki hashes notification channel names with xxhash, so a multi-shard notify group must use an xxhash default shard index.

531 — COPY FROM PROGRAM is unavailable.

Use COPY ... FROM STDIN and send the data from the client.

Advisory locks

Codes raised when the router cannot place an advisory lock on a single shard, or take it at all.

60 — A session cannot hold session advisory locks on multiple shards.

Depends on the data topology: user_data is the advisory-lock shard group, and keys 1 and 2 hash to different shards. A session holds its session-level locks on one shard, so release the first lock before taking one that lands elsewhere.

61 — Mixing session and transaction advisory locks is unavailable.

The statement mixes a session-scoped and a transaction-scoped advisory lock. Use one scope.

139 — Advisory locks are unavailable in this plan position.

The advisory-lock call lands in a plan position — the body of CREATE TABLE AS — where the router cannot take the lock. Take the lock in a separate statement.

Temporary tables

Codes raised for temporary objects. A session can create a temporary table with CREATE TEMP TABLE and a column list or with CREATE TEMP TABLE ... AS SELECT, insert into it with a VALUES list or a SELECT, and update, delete, merge and read it, in or out of a transaction block. It can also run TRUNCATE, VACUUM, ANALYZE, DROP TABLE, CREATE INDEX and DROP INDEX on it, and create enum, composite, and domain types, functions, and operators in its pg_temp schema. The data topology places a temporary table through the pg_temp schema, as the example schema does. Anything else that creates, names, or reads a temporary object is rejected before a shard sees it.

338 — Creating this temporary relation is unavailable.

A temporary relation is created by CREATE TEMP TABLE with a column list or by CREATE TEMP TABLE ... AS SELECT. Temporary views and materialized views, CREATE TEMP SEQUENCE, and a CREATE TEMP TABLE that the data topology places on a reference table or on a sharded shard group without a sharding key report the same code. Create a regular relation and drop it when done.

544 — … that depends on an object in schema pg_temp is unavailable.

The table moods outlives the session, but the type pg_temp.mood exists only in this session, and no shard has it. The message names the rejected statement, here CREATE TABLE. Create the type outside pg_temp, or create the dependent object in pg_temp.

581 — A type, routine or operator name or OID that a shard reads is unavailable when it can name an object in schema pg_temp.

The statement stores the OID of the temporary type mood in a table. A shard has none of the session’s objects in pg_temp, so the OID means nothing there. Store the name, such as 'pg_temp.mood'::regtype::text.

612 — … in schema pg_temp, which a temporary table needs, reaches an object of schema pg_temp that cannot be created on the shards yet.

A temporary table lives on the shards, so the domain of its column has to exist there too, with everything its CHECK calls. The router cannot create a temporary operator on the shards yet. Use a CHECK that calls no operator of pg_temp.

682 — … on an object in schema pg_temp is unavailable.

The router keeps the session’s objects in pg_temp itself and cannot translate every form of DDL on them. The message names the rejected statement, here ALTER FUNCTION. The router accepts SET work_mem = '64MB'.

690 — A relation or type name passed as a string or a bound parameter is unavailable when it can name a temporary table.

The default 'session_cart' is a name in a string, which a shard resolves, and the router cannot route a shard to the session’s temporary tables. Name the table in the statement itself.

701 — … whose stored expression calls a routine that reads a temporary table is unavailable.

The shards evaluate a CHECK, a DEFAULT, or another stored expression against the rows they have, and each shard has only its own rows of a temporary table. cart_size reads session_cart, so it would not see the whole table. The message names the statement the router would send to the shards for the change. Read the temporary table outside the stored expression.

717 — DDL that names an object spelled like a temporary table is unavailable while the session has temporary tables.

The new type has the same name as the temporary table session_cart. The router cannot tell whether the statement names the temporary table or a new object, so it rejects the statement. Choose a name that no temporary table has, or run DISCARD TEMP first.

749 — … on a temporary table is unavailable.

Temporary tables support CREATE TEMP TABLE, CREATE TEMP TABLE AS, SELECT, INSERT, UPDATE, DELETE and MERGE, and TRUNCATE, VACUUM, ANALYZE, DROP TABLE, CREATE INDEX and DROP INDEX of only temporary tables. The message names the rejected statement, here ALTER TABLE.

753 — Sending a value of type …, a type in schema pg_temp, to a shard is unavailable.

The router computes an expression of a type in pg_temp itself, but the INSERT would send the value to a shard, which has no such type. Cast the value to a type outside pg_temp, such as 'happy'::pg_temp.mood::text, where the router computes it.

790 — A routine outside schema pg_temp whose LANGUAGE sql body or PL/pgSQL declarations name an object in pg_temp is unavailable.

Each shard checks the body when it creates the routine, without the session’s objects in pg_temp. Create the routine in pg_temp, or write it in PL/pgSQL, where a statement can name the table because it resolves when the routine runs. A PL/pgSQL declaration cannot name a pg_temp object: it resolves when the routine compiles, before the session’s temporary objects exist.

794 — … on an object in schema pg_temp that references an object created outside pg_temp in the same transaction is unavailable.

The shards do not have shade until the transaction commits, so the router cannot create the domain that depends on it. The message names the rejected statement, here CREATE DOMAIN. Commit the transaction that creates the other object first.

870 — … that cascades to an object in schema pg_temp is unavailable.

CASCADE would also drop pg_temp.primary_color, which depends on color. The message names the rejected statement, here DROP TYPE. Drop the objects in pg_temp that depend on the type first.

915 — Using a temporary table or reading the system catalog is unavailable on shard …, which this transaction reached on a connection that does not hold the session’s temporary tables.

The session holds shard-meta for its temporary table, but in atomic transaction mode SELECT * FROM notes reached that shard on a connection from the pool, which does not hold the session’s tables. Run the statement in a new transaction.

917 — The storage size of a temporary relation is unavailable.

A temporary table exists only on the session’s own backend, which the router’s size probe cannot reach. The size functions pg_relation_size, pg_table_size, pg_indexes_size and pg_total_relation_size work for tables that are not temporary.

919 — … naming objects both in schema pg_temp and in other schemas is unavailable.

One DROP FUNCTION names a function in pg_temp and one in public. The message names the rejected statement. Run one statement for the objects in pg_temp and another for the rest.

PL/pgSQL

Codes raised while translating or executing a PL/pgSQL routine on the router.

86 — Record fields with varying runtime types are unavailable in PL/pgSQL.

FETCH reads its columns’ types only when it runs, so r.f1 is an integer on one iteration and a numeric on the other. Give the field the same type on every path, for example with a cast.

87 — Function configuration parameters are unavailable for router-side execution.

The function’s SET clause names a parameter the router cannot scope around a call, here the Neki session option __neki.target. Set it on the session instead.

90 — This PL/pgSQL statement is unavailable.

A PL/pgSQL statement form the executor has no implementation for, here GET DIAGNOSTICS ... PG_CONTEXT.

569 — Reading a record outside the statements that follow its assignment from a non-constant EXECUTE command string or a cursor the routine does not open is unavailable.

The command string q is built at run time, so only the statements after the EXECUTE in the same block know the shape of r. The read of r.a comes after the inner block ends. Read the record in the block that fills it.

632 — DO blocks in a language other than PL/pgSQL are unavailable.

A DO block runs only in PL/pgSQL on Neki. Write the block in PL/pgSQL.

757 — DISTINCT, and an ORDER BY, GROUP BY or DISTINCT ON key naming the result column, are unavailable in a PL/pgSQL assignment that coerces its value or assigns an array element.

The assignment coerces its value (here numeric to int) and its query uses DISTINCT. Cast the value in the query, or assign without DISTINCT.

764 — A record that a PL/pgSQL function reads from a cursor it does not open is unavailable.

The caller opened the cursor with SQL DECLARE, so the router cannot know the shape of the row the function fetches. Open the cursor in the function with OPEN over a static query, or fetch into scalar variables.

844 — Reading a PL/pgSQL cursor over a data-modifying query or an EXPLAIN after search_path, the role, or the shard or sidecar target changed since its OPEN is unavailable.

The cursor is over an EXPLAIN, and search_path changed between its OPEN and the FETCH. Read the cursor before changing the setting.

935 — A record value of function … is unavailable on the router where its shape is needed: the function names no shape for it.

record_in makes a record of the row type that its second argument names. The argument is a variable, so only the run knows the type, and the router has no shape for the record. Pass a constant type, such as 'coordinates'::regtype::oid.

Query shapes and routing

The largest group: codes raised while the planner turns a query into routed work. Many depend on the data topology, and the same statement can plan against an unsharded table and be rejected against a sharded one.

69 — Subqueries in VALUES are unavailable.

A subquery inside a VALUES cell. Compute the value in a SELECT and feed it in, or use INSERT ... SELECT.

100 — Subqueries are unavailable in this DML clause.

A subquery appears in a DML clause that cannot host one — here the SET value of an UPDATE ... FROM. Move the subquery into the FROM source and reference its column.

101 — Per-row router-only expression evaluation is unavailable here.

The router evaluates current_setting itself, and its argument name is a column, so the router must evaluate it for each row. With FOR UPDATE, a shard has already locked those rows, so the router cannot filter them afterward. Remove the row lock, or do not pass a column to the function.

102 — This RETURNING expression extraction is unavailable.

RETURNING mixes an OLD/NEW row alias with an expression the router must evaluate itself, here now(). Return the columns and compute the router-side expression in your application.

103 — This DML source join cannot be planned safely.

The predicate bridging the DML target to its USING/FROM source is not something the planner can evaluate on one side, so the join cannot be executed safely.

104 — This mutation cannot maintain active secondary indexes.

Depends on the topology: accounts owns global secondary indexes, and this mutation shape cannot keep their lookup rows in step with the rows they point at.

106 — This window-function shape is unavailable across shards.

The router computes a window function over the rows it gathers from the shards, and it cannot sort a window by a custom USING operator across shards. Rejected only when the query actually spans shards. Use ASC or DESC, or filter on the shard key so that one shard runs the query.

107 — Expression extraction is unavailable in this clause.

A router-only expression (now()) appears in a clause the planner cannot lift it out of — here GROUP BY. Compute the value in your application and pass it as a parameter.

108 — This subquery shape is unavailable in ORDER BY.

An ALL subquery is the ORDER BY sort key, and the router cannot evaluate that shape. Sort by a column, or sort in your application.

109 — This quantified-subquery shape is unavailable.

The HAVING clause tests an aggregate against an IN subquery that reads the outer query (orders.user_id), so the router cannot pull the subquery up. Remove the reference to the outer query from the subquery.

110 — This correlated-subquery shape cannot be decorrelated safely.

The correlated subquery has its own GROUP BY, so decorrelating it would change which groups exist. Rewrite it as an explicit join.

111 — This lateral or range-function shape is unavailable.

A subquery as the argument of a function in FROM is the rejected part. Compute the argument in a CTE or a join instead.

112 — This full outer join has no usable equality key.

A full outer join needs an equality key it can hash on both sides; > does not give one. Join on an equality.

116 — This INSERT subquery shape is unavailable.

The subquery is nested inside a larger expression in the VALUES cell rather than being the whole cell. Use INSERT ... SELECT.

117 — This INSERT SELECT shape is unavailable.

The combination of an INSERT ... SELECT source with ON CONFLICT DO UPDATE against a sharded target returns this code, except when the source is one table in the same shard group and the inserted shard key is copied from that table’s shard key. Insert explicit VALUES, or drop the DO UPDATE. INSERT ... SELECT into a table sharded by an expression over more than one column also returns this code. INSERT ... VALUES into that table returns code 10.

118 — These INSERT values cannot be materialized on the router.

A set-returning function in a VALUES cell means the router cannot know the rows — and therefore the routing values — before executing. Expand the rows in your application, or use INSERT ... SELECT.

119 — This ON CONFLICT shape is unavailable.

Depends on the topology: the ON CONFLICT arbiter index (order_id) does not include the table’s shard key (user_id), so the router cannot match the rows that RETURNING produces to the rows you inserted. Arbitrate on an index that includes the shard key, insert one row per statement, or drop the WHERE or the RETURNING.

120 — This column default cannot be materialized on the router.

A reference table’s copies must all store the same value, so the router evaluates the default itself, and it cannot draw an identity value. Supply the value explicitly.

121 — This MERGE shape is unavailable.

The MERGE source is a derived table, so the planner cannot route the merge to the target’s shards. Use a MERGE whose source is a table in the same shard group.

122 — This view cannot be routed safely.

Depends on the topology: Neki does not route a write through a view whose underlying table is sharded, whatever the predicate. Write to the base table.

123 — This materialized view cannot be routed safely.

Depends on the topology. A materialized view over sharded data stores one shard’s result in a single heap, which a read cannot reassemble.

124 — This set-operation shape is unavailable.

INTERSECT and EXCEPT are not planned for application tables; only UNION is. This limit does not apply to statements Neki forwards unchanged.

125 — This grouping-set form is unavailable.

The GROUPING SETS (or ROLLUP/CUBE) form passes validation but has no cross-shard execution: each grouping set would need its own aggregation pass. Issue the grouping levels as separate queries.

126 — TABLESAMPLE is unavailable.

The TABLESAMPLE clause is rejected; a per-shard sample would not be a sample of the whole table. Sample with a WHERE predicate such as random() < 0.5.

128 — WHERE CURRENT OF is unavailable for DML.

WHERE CURRENT OF identifies a row by cursor position, which the router does not track across shards. Delete or update by key.

129 — DISTINCT cannot safely evaluate this volatile record expression.

DISTINCT would have to compare a record value built from a volatile function, whose result changes per evaluation, so duplicate elimination is not well defined.

130 — This combination of select-list subqueries is unavailable.

One select-list expression combines a router-only value with a correlated subquery; the two need incompatible evaluation strategies in the same slot. Split them into separate expressions or queries.

131 — TRUNCATE RESTART IDENTITY with CASCADE is unavailable.

RESTART IDENTITY together with CASCADE is rejected because the cascade set — and so the sequences to restart — is only known per shard. Truncate the tables explicitly.

132 — TRUNCATE RESTART IDENTITY cannot include descendant tables.

Depends on the schema: rejected when the table has descendants, since TRUNCATE would reach them and their sequences. Use TRUNCATE ONLY, or truncate each table separately.

133 — This whole-row reference is ambiguous to the SQL builder.

The whole-row reference t.* is shadowed by a column also named t, so the SQL builder cannot tell which the query means. Rename the column or the alias.

135 — Aggregates over columns of an enclosing query are unavailable.

The aggregate’s argument belongs to the enclosing query, so the aggregation happens at the outer level from inside the subquery. Compute the aggregate in the outer select list.

136 — Correlated column references are unavailable in this clause.

The correlated reference sits in LIMIT (or OFFSET), a clause that is evaluated once rather than per outer row. Pass the limit as a parameter.

138 — FETCH FIRST WITH TIES is unavailable across shards.

WITH TIES needs to know every row tied at the cut-off, which no single shard can determine. Use a plain LIMIT, or rank in a subquery and filter.

140 — Set-returning functions are unavailable in router-side ORDER BY.

A set-returning function in ORDER BY must be expanded on the router, which cannot happen while merging sorted streams from several shards. Move the expansion into the FROM clause.

141 — INSERT OVERRIDING USER VALUE is unavailable.

The OVERRIDING USER VALUE clause is the rejected part. Omit it, or use OVERRIDING SYSTEM VALUE where you need to write an ALWAYS identity column.

142 — Parameterized subscripts are unavailable in INSERT targets.

The subscript in the INSERT target list is a parameter, so the router does not know which element is being written at plan time. Use a literal subscript, or write the whole array.

143 — OLD and NEW references are unavailable in sharded INSERT ON CONFLICT RETURNING.

Depends on the topology: for a sharded target, OLD/NEW aliases in the RETURNING of an ON CONFLICT statement are not available. Return plain columns.

144 — Router-only expressions are unavailable in sharded INSERT ON CONFLICT RETURNING.

As code 143, for an expression the router must evaluate itself rather than an OLD/NEW reference. Return columns and compute the expression in your application.

145 — Updating an index column is unavailable.

The statement assigns to user_id, which is the table’s shard index column — changing it could move the row to another shard. Delete the row and insert the new one.

146 — This router-only WHERE expression is unavailable.

The volatile router-only call is buried inside another expression in WHERE, so the router cannot evaluate it once and route on the result. Compute the value first and pass it in.

147 — This volatile router-only UPDATE assignment is unavailable.

Both the assigned value and the predicate are volatile router-only expressions, so the rows to change and the values to write cannot be determined together. Select the rows first, then update them by key.

149 — Window functions inside aggregates are unavailable.

A plain aggregate and a window function appear in the same select list, which would need two incompatible aggregation passes across shards. Compute the window function over a subquery that does the aggregation.

150 — This ORDER BY expression is unavailable for VALUES.

The ORDER BY attached to a VALUES list is an expression rather than a plain column reference. Sort in the enclosing query instead.

151 — INTERSECT and EXCEPT subqueries are unavailable.

The subquery’s top level is an INTERSECT (or EXCEPT). Rewrite it as a join or an IN/NOT IN predicate, or use array functions.

152 — This subquery statement type is unavailable.

A VALUES list used as a scalar subquery is not a SELECT. Write (SELECT 1) instead.

153 — ARRAY subqueries are unavailable.

An ARRAY(...) subquery the router would have to evaluate, here in ORDER BY, is the rejected part. Use array_agg over a normal subquery: SELECT array_agg(order_id) FROM ....

576 — A whole-row reference to a join is unavailable.

j names the whole row of an aliased join. Select the columns you need instead.

597 — Nested grouped expressions in SELECT targets are unavailable.

The grouped expression appears nested inside a larger target expression. Select the grouped expression on its own, or group by a column.

604 — A volatile value used to choose the shards is unavailable.

current_user_id() is a volatile routine, so the router would evaluate it once to choose the shards and a shard would evaluate it again for every row, and the two can disagree. Route on a value that calls no volatile routine, or move the call into a scalar subquery so it is evaluated once.

733 — Tables ”…” from different schemas cannot both appear unaliased in one query.

Both tables are named notes. Give one of them an alias.

739 — JSON_ARRAY(query) evaluated by the router is unavailable.

JSON_ARRAY over a subquery, evaluated by the router. Use json_agg over the subquery instead.

798 — A record a shard builds is unavailable on the router when the statement builds records of other row types with the same field types: its field names, typmods or collations cannot be told apart.

Both branches of the CASE build a one-field record of type varchar, with different type modifiers. The max merges the records from every shard, and the router cannot tell from a shard’s reply which of the two row types a record has. The same happens when the branches differ in COLLATE. Give the records the same type modifier and COLLATE in every branch.

822 — A LATERAL XMLTABLE or JSON_TABLE is unavailable.

A LATERAL JSON_TABLE or XMLTABLE in FROM is the rejected part.

824 — Table ”…” shares its name with another table in the query, which a reference past a column alias list needs to tell apart.

The outer users u(a) renames its first column to a, and the subquery’s orders u reuses the name u. Give the two tables distinct aliases.

945 — Table ”…” inside an aliased join cannot share its name with another table in the query.

public.users sits inside the aliased join j, and the alias users names another table. Give the tables distinct names.

Evaluation engine

Codes raised when the router — rather than a shard — has to compute an expression and has no implementation for it. A query that a shard can evaluate on its own is unaffected.

64 — Set-returning function … has no opcode factory.

The router has no implementation of this set-returning built-in function, so it cannot run it.

200 — Built-in function … is unavailable in the evaluation engine.

The built-in function has a catalog entry but no router implementation, so it cannot be evaluated when the router — rather than a shard — has to compute it.

555 — … is unavailable on the router without a shard target.

A replication slot lives on one shard, and the router does not choose a shard for it. Pin the session to a shard with SET __neki.shard = '<shard_uid>' and run the call there. __neki.list_shards() lists the shard UIDs.

559 — pg_reload_conf is unavailable on the router.

The router has no PostgreSQL configuration to reload. Use __neki.reload_postgres(shard_uid, sidecar_uid) to ask one node to reread its configuration (needs the neki_operator role). __neki.list_sidecars() lists the UIDs to pass.

571 — pg_promote is unavailable on the router.

Promotion changes which node of a shard is the primary, and the router does not decide that. Use __neki.planned_switchover(shard_uid) to promote a replica without data loss (needs the neki_operator role). __neki.list_shards() lists the shard UIDs.

594 — … is unavailable for this index or access method.

The router has a handler only for the six built-in access methods and does not stream pg_am, so it cannot tell an OID that no access method has from the OID of a custom access method. PostgreSQL returns NULL for this OID.

DDL

Codes raised by the DDL surface, mostly for objects that are local to one Postgres host and so would not reach a shard that joins the cluster later.

300 — Creating an operator class is unavailable.

An operator class created through the router is not carried to a shard that joins the cluster later. Use one Postgres provides, or install one through an extension.

301 — Creating an operator family is unavailable.

As code 300: an operator family created here would not reach a later-joining shard.

302 — Creating a text search configuration is unavailable.

Router-side text-search evaluation supports only Postgres’s built-in configurations, so a user-created one could not be used by a routed text-search expression.

303 — Creating a text search dictionary is unavailable.

As code 302, for a text-search dictionary.

304 — Event triggers are unavailable.

Event triggers fire on DDL, which the router executes on every shard, so the trigger’s behavior is not well defined. ALTER EVENT TRIGGER is rejected the same way.

305 — Rewrite rules are unavailable.

A rewrite rule would change a statement’s meaning below the router, after planning and routing. Use a trigger, or do the rewrite in your application.

308 — Creating a tablespace is unavailable.

A tablespace is storage local to one Postgres host, so it is not carried to a later-joining shard. Use the default tablespace.

309 — Creating an access method is unavailable.

An access method needs a C handler local to the host and is not carried to a later-joining shard. Use a built-in method, or install one through an extension.

310 — Creating a collation is unavailable.

A collation created through the router is not carried to a later-joining shard, and rows sorted with it could then compare differently per shard. Use a collation Postgres already provides.

311 — Creating a conversion is unavailable.

As code 310, for an encoding conversion.

312 — Foreign data wrappers are unavailable.

Foreign data wrappers reach outside the cluster from a single host. Import the data into a Neki table, or reach the remote system from your application. ALTER FOREIGN DATA WRAPPER is rejected the same way.

313 — Creating a foreign server is unavailable.

A foreign server exists only to serve foreign data wrappers and foreign tables, neither of which Neki supports.

314 — Foreign tables are unavailable.

A foreign table’s data lives outside the cluster, so the router has no topology for it and cannot route to it.

315 — User mappings are unavailable.

User mappings apply only to foreign data wrappers, which Neki does not support. ALTER and DROP USER MAPPING are rejected the same way.

316 — Creating a text search parser is unavailable.

A text-search parser needs host-local C functions and is not carried to a later-joining shard. Use the built-in parser, or one an extension installs.

317 — Creating a text search template is unavailable.

As code 316, for a text-search template.

318 — Creating a transform is unavailable.

A transform created through the router is not carried to a later-joining shard. Install one through an extension.

319 — Changing composite-type attributes is unavailable.

Changing a composite type’s attributes rewrites every table using that type, which the router does not coordinate across shards. Create a new type and migrate to it.

320 — Shared library loading is unavailable.

LOAD loads a shared library into one Postgres backend, and it is not carried to a later-joining shard. Install the library on every shard host before starting Neki.

321 — IMPORT FOREIGN SCHEMA is unavailable.

IMPORT FOREIGN SCHEMA creates foreign tables, which Neki does not support (code 314).

323 — Per-column statistics overrides are unavailable.

A per-column statistics target is planner tuning local to one Postgres instance, so setting it through the router would not apply uniformly.

324 — Per-column foreign-table options are unavailable.

Per-column foreign-table options presuppose foreign tables, which Neki does not support (code 314).

325 — This function language is unavailable.

The function’s language is the rejected part: only SQL and PL/pgSQL are supported. A language other than those needs a handler local to the host.

326 — This procedure language is unavailable.

As code 325, for CREATE PROCEDURE.

327 — CREATE LANGUAGE with a handler is unavailable.

The HANDLER clause names a host-local C function. Install the language through a supported extension instead.

328 — Renaming a domain constraint is unavailable.

Renaming a domain constraint is rejected, while ALTER DOMAIN ... RENAME TO, SET SCHEMA, and OWNER TO are supported.

329 — ALTER DOMAIN is unavailable.

Changing a domain’s default or constraints affects every column using the domain, across shards, so the statement is rejected.

330 — The IS_TEMPLATE database option is unavailable.

The IS_TEMPLATE option is what is rejected; ALTER DATABASE ... IS_TEMPLATE reports the same code.

331 — Database tablespace selection is unavailable.

The TABLESPACE option on a database selects host-local storage (code 308). ALTER DATABASE ... SET TABLESPACE reports the same code.

332 — This database locale is unavailable to the router.

The named locale cannot be resolved by the routers, so the database would exist in a state the router could not read back. Use a locale every router provides, or the icu or builtin locale provider.

333 — Renaming an enum label used as a sharding key is unavailable.

regional_users is sharded on the enum column region, so renaming a label would change where existing rows route. The same statement is allowed for an enum not used as a sharding key.

334 — Column storage selection is unavailable.

The SET STORAGE action is the rejected part: Neki cannot preserve a column’s storage setting for a shard that joins the cluster later, so the setting would not be uniform across shards.

335 — Column compression selection is unavailable.

As code 334, for a column’s compression method.

336 — Changing a routing column’s generated expression is unavailable.

account_id is both a generated column and the shard key of regional_accounts. Changing or dropping its generation expression could send existing rows to another shard without moving them. The same change is allowed for a generated column that does not drive routing.

337 — Restarting an identity column through ALTER TABLE is unavailable.

Neki cannot reset the router’s reservations for the identity sequence. Restart the column’s owned sequence with ALTER SEQUENCE instead.

339 — Temporary range, shell and base types are unavailable.

A temporary enum, composite, or domain type works. A range type also creates companion types and functions, a shell type has no definition yet, and a base type has input and output functions, and the router’s temporary layer carries none of these. Create a regular type and drop it when done.

341 — Temporary statistics are unavailable.

Temporary statistics would be created on each shard’s pooled backend, where they outlive the session. Create regular statistics and drop them when done.

342 — This database encoding is unavailable to the router.

The router reads and evaluates text as UTF-8. Use UTF8, the default, or another encoding the router supports.

343 — Converting an existing table to a typed table is unavailable.

Neki cannot restore the typed-table relationship when a shard joins.

347 — Attaching or detaching partitions with different routing is unavailable.

Depends on the topology: the partition is not configured in the data topology, so attaching it would change how its rows are routed.

348 — Changing all triggers through ALTER TABLE is unavailable.

Neki cannot restore an ALL change to a shard that joins later. Name the trigger, or use the USER form.

351 — LISTEN, UNLISTEN and NOTIFY are unavailable in stored expressions shards evaluate.

A stored expression runs on the shard that performs the write, not on the notification channel’s shard, so the notification would never reach a listener.

515 — A recursive CTE with a composite-typed column is unavailable on the router.

The recursive CTE crosses shards and carries a composite column, whose type the router cannot carry through this recursive plan.

554 — A multiply referenced MATERIALIZED CTE returning an anonymous record with a non-static shape is unavailable on the router.

The two references share a materialized result, but the record has a different number of fields in each CASE branch. Use a fixed record shape.

568 — Creating user-defined base types is unavailable.

Neki rejects both shell declarations and complete definitions of user-defined base types. Install a custom base type through an extension available on every shard.

573 — A data-modifying CTE statement that reads a written table outside a pre-write stage is unavailable on the router.

The outer query reads users, which the data-modifying CTE writes, outside the stage that runs before the write.

579 — This data-modifying CTE body is unavailable on the router.

The MERGE body cannot be hosted by the router CTE materialization boundary.

586 — A recursive CTE read more than once, whose recursion runs on one shard, is unavailable.

The recursion joins users on its shard key, so the router runs it as one shard statement, which serves one reference. The query reads chain twice. This rejection depends on the data topology. Read the CTE once.

593 — Recursive CTE ”…” with a SEARCH or CYCLE clause is unavailable when its recursion cannot run on one shard.

The recursive term joins on name, not on the shard key, so the recursion cannot run on one shard. The router then runs it one step at a time, and it does not compute the SEARCH or CYCLE column, which PostgreSQL derives from the row each new row came from. Join the recursive term on the shard key so the whole recursion runs on one shard.

626 — Refreshing a database collation version is unavailable.

Neki manages collation versions across shards.

631 — Nested CTE name shadowing is unavailable on the router.

The CTE a inside t shadows the data-modifying CTE a. Give the inner CTE a distinct name.

635 — A recursive CTE whose body holds a WITH clause of its own, or a WITH RECURSIVE item referenced before its definition, is unavailable on the router.

The body of the recursive CTE r holds its own WITH clause, q. Define q before r in the outer WITH clause.

640 — A routine that runs a utility statement or dynamic SQL is unavailable in SQL that shards run without the router.

A trigger function runs on the shard that holds the row, so the TRUNCATE would act on that shard’s part of notes alone. Creating the function succeeds; creating the trigger that stores it is refused. Run the statement outside the trigger.

645 — A data-modifying CTE body whose output differs from its write’s RETURNING columns is unavailable on the router.

The router-computed now() output does not match the write producer’s RETURNING columns. This rejection depends on the query plan and data topology.

659 — A TRUNCATE that removes rows of a global secondary index owner table it does not name is unavailable.

accounts has global secondary indexes, so the router empties their lookup tables when a TRUNCATE empties accounts. Here CASCADE empties accounts through its foreign key, and the statement does not name it, so the router cannot find its lookup tables. Name accounts in the TRUNCATE.

661 — A CASCADE TRUNCATE is unavailable in a transaction that changed schema the router could not mirror.

The router cannot apply ALTER TABLE ... REPLICA IDENTITY to its schema view inside a transaction. It then cannot tell which foreign keys the CASCADE follows. Commit or roll back the transaction, then run the TRUNCATE.

696 — ALTER EXTENSION membership changes are unavailable.

Develop extension membership outside Neki, then apply an extension update with ALTER EXTENSION ... UPDATE.

698 — CREATE DATABASE with an explicit OID is not supported; omit the OID option.

Omit the OID option.

700 — Changing base-type I/O options is unavailable.

The SET option changes a base type’s input or output functions. Neki cannot refresh the router’s type metadata after that change, so it rejects the statement before it reaches a shard.

705 — Data-modifying CTE ”…” read through CTE ”…”, which the planner copies for each of its references, is unavailable on the router.

The CASE returns rows of different sizes, so v returns a record of no fixed shape. The outer query reads a twice, which reads v, so the planner copies a for each reference, and each copy would run the UPDATE in v. Give both branches of the CASE the same row shape, read a once, or filter on the shard key user_id, which keeps the statement on one shard.

707 — A data-modifying CTE read by a query block the planner eliminates, or by a CTE that does not run, is unavailable on the router.

The only query block that reads inserted has a constant-false WHERE, so the planner drops it, and with it the reference that keeps the INSERT in the plan. PostgreSQL still runs the INSERT. Remove the condition, or read inserted from a block that runs.

711 — A set-returning function in a target list an aggregation combines across shards is unavailable.

The aggregate combines rows from every shard, and generate_series in the same target list changes the rows it combines. Move the set-returning function into the FROM clause.

786 — A data-modifying CTE whose write the router feeds, writing a table with triggers, rewrite rules, cascading foreign keys or partitions, is unavailable on the router.

The router runs this UPDATE once for each shard, so the statement-level trigger products_price_changed would fire more than once for one statement. Any trigger on the written table that fires for the CTE’s command (UPDATE or DELETE) causes this rejection, also when the trigger is disabled. The router rejects the statement for the same reason when the written table:
  • is referenced by a foreign key whose ON UPDATE or ON DELETE action for that command is CASCADE, SET NULL or SET DEFAULT, because PostgreSQL runs that action as a trigger;
  • has a rewrite rule for that command. Neki rejects CREATE RULE (code 305), so only a rule created outside Neki can cause this;
  • is a partition, a partitioned table, or an inheritance parent that the statement writes without ONLY.
Run the write as a statement of its own, or remove the trigger. This rejection depends on the data topology.

787 — A query using … cannot be forwarded to the shard the session targets, because the router evaluates it.

With __neki.shard set, the router sends the statement to one shard as written. current_setting reads the session’s settings, which the router evaluates, so the statement cannot be sent whole. Read the setting in a separate statement.

801 — A whole-row CTE reference with a target-list subquery is unavailable on the router.

The whole-row reference includes a subquery that the planner has extracted from the CTE target list. Select the individual columns instead of the whole row.

803 — Session state is unavailable in stored expressions shards evaluate.

A trigger function runs on a shared shard connection, where a session-level SET would outlive the statement and reach other sessions. Creating the function succeeds; creating the trigger that stores it is refused. Use SET LOCAL.

810 — A NOT MATERIALIZED SELECT CTE read more than once by a statement with a data-modifying CTE is unavailable on the router.

batch is read by the UPDATE and by the outer query. Mark it MATERIALIZED.

816 — A data-modifying CTE body without verifiable write output columns is unavailable on the router.

The INSERT ... SELECT reads a join across shards, so the router runs the write below its own operators, and the CTE has no RETURNING clause from which it could verify the write’s output columns. This rejection depends on the data topology. Add a RETURNING clause.

821 — A CTE exposing an unnamed subquery column is unavailable on the router.

The extracted subquery has no output name in the CTE body. Give the expression an explicit alias inside the CTE.

838 — Renaming table … to … is unavailable: the data topology declares routing for the new name, but the router cannot verify the table it renames.

The data topology declares routing for orders, but the router finds no table orders_staging to check against it. Create the table, wait for the router to see it, then rename it.

882 — A volatile subquery in a SELECT list whose ORDER BY reads it, beside a shard-evaluated set-returning function, is supported only when it runs on the same shard as its outer query.

each runs on the shard, and the ORDER BY reads the volatile subquery s, which correlates on order_id and so runs in the router. The router would run it once for each row that each returns, where PostgreSQL runs it once for each row of users. Correlate the subquery on the shard key, o.user_id = u.user_id, or move each into the FROM clause.

888 — Recursive CTE ”…” carries a column whose type has no array type, which is unavailable on the router.

The recursive term joins on order_id, not on the shard key, so the recursion cannot run on one shard. The router then binds every carried column as an array of its type, and tags is already an array, which PostgreSQL has no array type for. Join the recursive term on the shard key so the whole recursion runs on one shard.

896 — SECURITY LABEL statements are unavailable.

Neki does not yet install a security label provider, so it rejects SECURITY LABEL statements for all object types.

900 — This CREATE TABLE AS body cannot be populated safely.

Depends on the topology: the new table has no routing configured, so the router cannot tell where its rows would be read. Create the table WITH NO DATA, add routing for it, then fill it with INSERT ... SELECT. A topology update is a complete replacement, not a partial patch. Retrieve the current document, add the new table to the shard group the source rows are read from — beside users, under databases.app.schemas.public.tables — and re-apply it:
The group’s default shard index routes on user_id, which the copied table keeps.

902 — CREATE TABLE AS EXECUTE is unavailable.

Write the prepared query into the CREATE TABLE AS in place of EXECUTE.

905 — GROUP BY or DISTINCT on column ”…” of CTE ”…”, which an outer join inside the CTE body can null, is unavailable on the router.

c.user_id comes from the nullable side of the CTE’s LEFT JOIN, and the outer query groups by it. Mark the CTE AS MATERIALIZED, or write it as a derived table.

910 — View … is unavailable through the router, because an UPDATE through it would write the setting column of pg_settings.

An UPDATE through the view would write the setting column of pg_settings, which the router evaluates itself. Leave setting out of the view, or read pg_settings directly.

921 — A reference-table UPDATE FROM with … is unavailable.

Every copy of a reference table runs the statement, and the volatile predicate that reads c.name can select different rows in each copy. Remove the volatile call from the WHERE clause, or write the statement without FROM.

933 — This nested CTE inside a data-modifying statement is unavailable on the router.

The CTE picked reads the CTE recent, and the UPDATE reads both. Mark picked as AS MATERIALIZED, or read recent directly. This rejection depends on the query plan and data topology.

961 — This nested recursive CTE is unavailable on the router.

The recursive CTE is nested through another CTE reference. This rejection depends on the query plan and data topology.

967 — A nested CTE referenced more than once is unavailable on the router.

The body of c2 references another CTE, c1, and the statement references c2 twice in a statement that writes. A SELECT with the same CTEs can plan. This rejection depends on the query plan and data topology.

972 — A data-modifying CTE that no running part of the statement reads, which references another CTE, is unavailable on the router.

The final query does not reference the second data-modifying CTE, whose body reads the first CTE. The router cannot execute this dependency chain as an unreferenced body.

976 — A GRANT or REVOKE whose change to a global secondary index lookup table the current role cannot make is unavailable.

account_logins uses the global secondary index by_email, so Neki keeps the privileges of its lookup table, accounts_by_email, in step with the tables that use the index. It makes that change as the current role, and report_owner does not own the lookup table. Run the statement as a superuser or as the owner of the lookup table.

981 — Changing a shard-index routing column is unavailable.

user_id drives routing, and changing it would alter routing without moving existing rows.

983 — A read that can stop before the end of a CTE that locks rows, or skip it, is unavailable on the router when one shard query cannot decide that as PostgreSQL does.

EXISTS can stop at the first row, but the CTE c locks every row of orders on every shard, and one shard query cannot decide how far PostgreSQL would read. Lock the rows in a separate statement.

992 — A data-modifying CTE body with ON CONFLICT is unavailable on the router.

The data-modifying CTE uses ON CONFLICT. This rejection depends on the query plan and data topology.

1018 — A data-modifying CTE returning an anonymous record with a non-static shape is unavailable on the router.

The RETURNING record has a different number of fields in each CASE branch. The router cannot serialize this record through the CTE materialization boundary. Use a fixed record shape.

Need help?

Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.