You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "duerwuyi (via GitHub)" <gi...@apache.org> on 2025/12/18 06:48:44 UTC

[I] PostgreSQL: sharding value extraction fails for typed timestamp constants in INSERT, causing error 20087 [shardingsphere]

duerwuyi opened a new issue, #37422:
URL: https://github.com/apache/shardingsphere/issues/37422

   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   
   shardingsphere-proxy 5.5.2
   postgres 17.2 as backend
   
   ### Expected behavior
   
   insertion succeed in all three types of timestamp.
   
   ### Actual behavior
   
   `TIMESTAMP '...'` is a typed literal of PG, should be routed as a normal literal, instead of an error.
   Furthermore, we suggest supporting routing `make_timestamp()` when its arguments are all literals.
   
   ```sql
   testdb=> CREATE SHARDING TABLE RULE t100 ( STORAGE_UNITS(ds_0,ds_1,ds_2,ds_3,ds_4), SHARDING_COLUMN=colocated_key, TYPE(NAME="AUTO_INTERVAL", PROPERTIES( "datetime-lower"="1970-01-01 00:00:00", "datetime-upper"="1980-01-01 00:00:00", "sharding-seconds"="86400" )) ); 
   SUCCESS 
   
   testdb=> create table t100 ( vkey int4 , pkey int4 , c0 numeric , colocated_key timestamp ); 
   CREATE TABLE 
   
   testdb=> INSERT INTO t100 (vkey, pkey, c0, colocated_key) VALUES (2, 12000, -479737441.3639, TIMESTAMP '1973-06-03 10:30:01'); 
   ERROR: Please check your sharding conditions 'ShardingConditions(conditions=[ShardingCondition(values=[], startIndex=0)], sqlStatementContext=org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext@5f864204, rule=org.apache.shardingsphere.sharding.rule.ShardingRule@1ec5ef0e, subqueryContainsShardingCondition=true)' to avoid same record in table 't100' routing to multiple data nodes.
   
   testdb=> insert into t100 (vkey, pkey, c0, colocated_key) values 
   (2, 12000, -479737441.3639, make_timestamp(1973, 6, 3, 10, 30, 1));
   ERROR:  Please check your sharding conditions 'ShardingConditions(conditions=[ShardingCondition(values=[], startIndex=0)], sqlStatementContext=org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext@87683f2, rule=org.apache.shardingsphere.sharding.rule.ShardingRule@79a00d3b, subqueryContainsShardingCondition=true)' to avoid same record in table 't100' routing to multiple data nodes.
   
   testdb=> insert into t100 (vkey, pkey, c0, colocated_key) values 
   (2, 12000, -479737441.3639,'1973-06-03 10:30:01');
   INSERT 0 1
   ```
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   
   [ss_postgres.zip](https://github.com/user-attachments/files/24228864/ss_postgres.zip)
   
   run `docker compose up -d` in this file.
   
   SQL to execute are shown above
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] PostgreSQL: sharding value extraction fails for typed timestamp constants in INSERT, causing error 20087 [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #37422: PostgreSQL: sharding value extraction fails for typed timestamp constants in INSERT, causing error 20087
URL: https://github.com/apache/shardingsphere/issues/37422


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] PostgreSQL: sharding value extraction fails for typed timestamp constants in INSERT, causing error 20087 [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #37422:
URL: https://github.com/apache/shardingsphere/issues/37422#issuecomment-3670279392

   Thanks for the report. 
   
   ShardingSphere currently extracts sharding keys only from simple literals or bound parameters. PostgreSQL typed literals (e.g., `TIMESTAMP '...'`) and values requiring function evaluation (e.g., `make_timestamp(...)`) are not used for sharding, which leads to this error. We’ve updated the documentation to note this limitation (see #37428).
   
   Please use plain literals or prepared-parameter forms for sharding keys so they can be extracted and routed correctly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org