pganalyze / pg_query

Ruby extension to parse, deparse and normalize SQL queries using the PostgreSQL query parser
BSD 3-Clause "New" or "Revised" License
778 stars 84 forks source link

Fails to build with PostgreSQL 16 #302

Closed jirutka closed 8 months ago

jirutka commented 11 months ago
Building native extensions. This could take a while...
current directory: dist/gems/pg_query-4.2.3/ext/pg_query
["/usr/bin/ruby", "extconf.rb"]
creating Makefile
current directory: dist/gems/pg_query-4.2.3/ext/pg_query
["make", "DESTDIR=", "sitearchdir=./.gem.20230929-21292-k62fo6", "sitelibdir=./.gem.20230929-21292-k62fo6", "clean"]

current directory: dist/gems/pg_query-4.2.3/ext/pg_query
["make", "DESTDIR=", "sitearchdir=./.gem.20230929-21292-k62fo6", "sitelibdir=./.gem.20230929-21292-k62fo6"]
compiling dist/gems/pg_query-4.2.3/ext/pg_query/guc-file.c
compiling dist/gems/pg_query-4.2.3/ext/pg_query/pg_query_ruby.c
compiling dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c: In function 'deparseJoinExpr':
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:3286:9: warning: enumeration value 'JOIN_RIGHT_ANTI' not handled in switch [-Wswitch]
 3286 |         switch (join_expr->jointype)
      |         ^~~~~~
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c: In function 'deparseCreateFunctionStmt':
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:4910:70: warning: left-hand operand of comma expression has no effect [-Wunused-value]
 4910 |                         if (IsA(create_function_stmt->sql_body, List), linitial((List *) create_function_stmt->sql_body) != NULL)
      |                                                                      ^
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c: In function 'deparsePartitionSpec':
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:5111:51: error: incompatible type for argument 2 of 'appendStringInfoString'
 5111 |         appendStringInfoString(str, partition_spec->strategy);
      |                                     ~~~~~~~~~~~~~~^~~~~~~~~~
      |                                                   |
      |                                                   PartitionStrategy
In file included from /usr/include/postgresql/16/server/utils/elog.h:19,
                 from /usr/include/postgresql/16/server/postgres.h:46,
                 from dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:1:
/usr/include/postgresql/16/server/lib/stringinfo.h:114:64: note: expected 'const char *' but argument is of type 'PartitionStrategy'
  114 | extern void appendStringInfoString(StringInfo str, const char *s);
      |                                                    ~~~~~~~~~~~~^
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c: In function 'deparseAlterTableCmd':
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:6160:22: error: 'AT_AddColumnRecurse' undeclared (first use in this function)
 6160 |                 case AT_AddColumnRecurse: /* internal to commands/tablecmds.c */
      |                      ^~~~~~~~~~~~~~~~~~~
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:6160:22: note: each undeclared identifier is reported only once for each function it appears in
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:6221:22: error: 'AT_DropColumnRecurse' undeclared (first use in this function); did you mean 'AT_DropColumn'?
 6221 |                 case AT_DropColumnRecurse: /* internal to commands/tablecmds.c */
      |                      ^~~~~~~~~~~~~~~~~~~~
      |                      AT_DropColumn
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:6233:22: error: 'AT_AddConstraintRecurse' undeclared (first use inthis function); did you mean 'AT_AddConstraint'?
 6233 |                 case AT_AddConstraintRecurse: /* internal to commands/tablecmds.c */
      |                      ^~~~~~~~~~~~~~~~~~~~~~~
      |                      AT_AddConstraint
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:6248:22: error: 'AT_ValidateConstraintRecurse' undeclared (first use in this function); did you mean 'AT_ValidateConstraint'?
 6248 |                 case AT_ValidateConstraintRecurse: /* internal to commands/tablecmds.c */
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                      AT_ValidateConstraint
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:6258:22: error: 'AT_DropConstraintRecurse' undeclared (first use in this function); did you mean 'AT_DropConstraint'?
 6258 |                 case AT_DropConstraintRecurse: /* internal to commands/tablecmds.c */
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~
      |                      AT_DropConstraint
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c: In function 'deparseGrantRoleStmt':
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:7957:58: error: 'GrantRoleStmt' has no member named 'admin_opt'
 7957 |         if (!grant_role_stmt->is_grant && grant_role_stmt->admin_opt)
      |                                                          ^~
dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.c:7976:57: error: 'GrantRoleStmt' has no member named 'admin_opt'
 7976 |         if (grant_role_stmt->is_grant && grant_role_stmt->admin_opt)
      |                                                         ^~
make: *** [Makefile:247: dist/gems/pg_query-4.2.3/ext/pg_query/postgres_deparse.o] Error 1
olleolleolle commented 11 months ago

To understand why that is, see #299, where an update to the supported-right-now version is described. EDIT: TIL that this would be unrelated, thanks!

jirutka commented 11 months ago

This isn’t a glibc issue, I’m building it on Alpine Linux with musl libc.

lfittl commented 11 months ago

I think this is a problem with the include path - it appears that your libpg_query build is somehow pulling in the system's Postgres headers before looking at the local headers it should be using.

It would be helpful if you could confirm whether this can be reproduced in isolation, for example if you attempt to install the Ruby gem in an empty Alpine Linux system / container. If you could share the steps to reproduce with a container, that would make it easiest to investigate whether we can fix the include paths here.

I believe that this should be entirely unrelated to the fact that libpg_query isn't updated for Postgres 16 yet (FWIW, we're already working on that), and is a problem that should be fixed independently, since the Postgres headers installed in the system do not need to match the libpg_query version in use.

jirutka commented 11 months ago

Okay, I’ll look at it, but please note that I maintain the ruby-pg_query since Alpine v3.14, i.e. it works with PostgreSQL 13, 14, 15 and fails just with PostgreSQL 16.

lfittl commented 8 months ago

Closing this since v5.0.0 has been released, which is based on Postgres 16. Let us know if you're still seeing any issues!