pganalyze / libpg_query

C library for accessing the PostgreSQL parser outside of the server environment
BSD 3-Clause "New" or "Revised" License
1.17k stars 172 forks source link

Ability To Increase NAMEDATALEN #258

Open david-h-muller opened 3 weeks ago

david-h-muller commented 3 weeks ago

Hello, we use libpg_query via pg_query_go. We are interested in increasing the value of NAMEDATALEN from its default value of 64.

Is there a way to increase the value of NAMEDATELEN via libpg_query or pg_query_go? (As far as I can tell, you can’t override NAMEDATALEN e.g. via pg_query_go’s cgo CFLAGS without first modifying the underlying source in libpg_query, but maybe I’m missing something).

What would be the best way to go about adding support for configurable NAMEDATALEN values?

lfittl commented 3 weeks ago

Hello, we use libpg_query via pg_query_go. We are interested in increasing the value of NAMEDATALEN from its default value of 64.

Can you share more about the use case where this is helpful?

Since Postgres itself has this limit, we match that in libpg_query.

Is there a way to increase the value of NAMEDATELEN via libpg_query or pg_query_go? (As far as I can tell, you can’t override NAMEDATALEN e.g. via pg_query_go’s cgo CFLAGS without first modifying the underlying source in libpg_query, but maybe I’m missing something).

Correct, today there isn't a way to do this, though it may be possible to support a define here in the future (not sure if there is a good way to have that be passed down frompg_query_go though).

david-h-muller commented 2 weeks ago

Can you share more about the use case where this is helpful?

We use pg_query_go / libpg_query to parse SQL statements destined for several different database backends (e.g. postgres, and trino, and clickhouse etc.). Some of those databases support identifiers longer than ~64 characters, so we’d like to be able to increase the limit.

Since Postgres itself has this limit, we match that in libpg_query.

Agreed, I think libpg_query is doing the right thing in propagating Postgres’s default limit, and I don’t want to change the default behavior.

(not sure if there is a good way to have that be passed down frompg_query_go though).

My thought was to… (1) Update the #define NAMEDATALEN in libpg_query with an #IFNDEF via a libpg_query patch/ file…e.g. to generate this final output in src/postgres/include/pg_config_manual.h:

#ifndef NAMEDATALEN
#define NAMEDATALEN 64
#endif

(2) Then, users could build pg_query_go with a modified NAMEDATALEN value using the CGO_CFLAGS env var… e.g. to increase NAMEDATALEN to 128:

CGO_CFLAGS="-DNAMEDATALEN=128" go build ...

Go merges the CGO_CFLAGS env var, with anything you might define in the source: "When building, the CGO_CFLAGS, CGO_CPPFLAGS, CGO_CXXFLAGS, CGO_FFLAGS and CGO_LDFLAGS environment variables are added to the flags derived from these directives.