Skip to content

在高版本的PostgreSQL上执行可能会出现字典创建失败的异常 #88

Description

@chasoneil

replay condition

  1. scws v 1.2.3 & zhparser-master & postgresql v15.2
  2. install zhparser
[postgres@localhost bin]$ ./psql 
psql (15.2)
Type "help" for help.

postgres=# \c test_zhpr;
You are now connected to database "test_zhpr" as user "postgres".
test_zhpr=# create extension zhparser;
CREATE EXTENSION
test_zhpr=# SELECT * FROM ts_parse('zhparser', '保障房资金压力');
NOTICE:  zhparser add dict : "/chason/postgres/code/pg15/data/base/zhprs_dict_test_zhpr.txt" failed!
 tokid | token 
-------+-------
   118 | 保障
   110 | 房
   110 | 资金
   110 | 压力
(4 rows)

There is a error print after execute SQL.

Reason

postgreSQL 15.2 and other versions base directory path changed!

[postgres@localhost base]$ ls 
1  16394  4  5
[postgres@localhost base]$ pwd
/chason/postgres/code/pg15/data/base

there is more level by database id. so we need to change code from zhparser.c

/**
	 * %s datadir is the data directory of the current database
	 * %s get_database_name(MyDatabaseId) is the name of the current database
	*  add mydatabaseId to path
	 */
	snprintf(dict_path, MAXPGPATH, "%s/base/%d/zhprs_dict_%s.txt",
			DataDir, MyDatabaseId, get_database_name(MyDatabaseId));

and then, there is no error after execute the SQL.

[postgres@localhost bin]$ ./psql 
psql (15.2)
Type "help" for help.

postgres=# \c test_zhpr;
You are now connected to database "test_zhpr" as user "postgres".
test_zhpr=# create extension zhparser;
CREATE EXTENSION
test_zhpr=# SELECT * FROM ts_parse('zhparser', '保障房资金压力');
 tokid | token 
-------+-------
   118 | 保障
   110 | 房
   110 | 资金
   110 | 压力
(4 rows)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions