用户登录
用户注册

分享至

postgresql类型转换

  • 作者: 爱吃h泡菜o221呃呃答天我
  • 来源: 51数据库
  • 2020-09-29
postgres=# create table t (id varchar);CREATE TABLEpostgres=# insert into t values ('1');INSERT 0 1postgres=# CREATE FUNCTION varcharinteq(varchar,int) RETURNS booleanpostgres-# AS $$ SELECT $1=$2::varchar $$postgres-# LANGUAGE SQL;CREATE FUNCTIONpostgres=# create operator = (procedure=varcharinteq,LEFTARG='varchar',RIGHTARG='int4');CREATE OPERATORpostgres=# select * from t where id=1; id ---- 1(1 row)postgres=# CREATE FUNCTION intvarchareq(int,varchar) RETURNS boolean AS $$ SELECT $1::varchar=$2 $$ LANGUAGE SQL;CREATE FUNCTIONpostgres=# create operator = (procedure=intvarchareq,LEFTARG='int4',RIGHTARG='varchar');CREATE OPERATORpostgres=# select * from t where 1=id; id ---- 1(1 row)



  回复 digoal 多谢,看来相当复杂



  看来9还反而严格了..
软件
前端设计
程序设计
Java相关