Skip to content

Commit

Permalink
Merge pull request #22 from longqimin/dev
Browse files Browse the repository at this point in the history
cherry-pick 15-4.2.2 to 15-4.2.3
  • Loading branch information
longqimin authored Nov 21, 2023
2 parents c5ddda4 + 91d1093 commit 9430c43
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All versions are tagged by the major Postgres version, plus an individual semver for this library itself.

## 15-4.2.3 2023-07-07

* Fix builds when compiling with `glibc >= 2.38` [#203](https://github.com/pganalyze/libpg_query/pull/203)
* Deparser: Add support for COALESCE and other expressions in LIMIT clause [#199](https://github.com/pganalyze/libpg_query/pull/199)

## 15-4.2.2 2023-07-07

* Deparser:
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PG_VERSION = 15.1
PG_VERSION_MAJOR = $(call word-dot,$(PG_VERSION),1)
PROTOC_VERSION = 3.19.6

VERSION = 4.2.2
VERSION = 4.2.3
VERSION_MAJOR = $(call word-dot,$(VERSION),1)
VERSION_MINOR = $(call word-dot,$(VERSION),2)
VERSION_PATCH = $(call word-dot,$(VERSION),3)
Expand Down Expand Up @@ -148,7 +148,8 @@ $(PGDIR):
echo "#undef USE_ARMV8_CRC32C" >> $(PGDIR)/src/include/pg_config.h
echo "#undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK" >> $(PGDIR)/src/include/pg_config.h
# Ensure we don't fail on systems that have strchrnul support (FreeBSD and NetBSD)
echo "#if defined(__FreeBSD__) || defined(__NetBSD__)" >> $(PGDIR)/src/include/pg_config.h
echo "#include <stdlib.h>" >> $(PGDIR)/src/include/pg_config.h
echo "#if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) || __GLIBC__ > 2))" >> $(PGDIR)/src/include/pg_config.h
echo "#define HAVE_STRCHRNUL" >> $(PGDIR)/src/include/pg_config.h
echo "#endif" >> $(PGDIR)/src/include/pg_config.h

Expand Down
3 changes: 2 additions & 1 deletion src/postgres/include/pg_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@
#undef HAVE__GET_CPUID
#undef USE_ARMV8_CRC32C
#undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK
#if defined(__FreeBSD__) || defined(__NetBSD__)
#include <stdlib.h>
#if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) || __GLIBC__ > 2))
#define HAVE_STRCHRNUL
#endif
12 changes: 8 additions & 4 deletions src/postgres_deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2267,9 +2267,11 @@ static void deparseSelectStmt(StringInfo str, SelectStmt *stmt)

if (IsA(stmt->limitCount, A_Const) && castNode(A_Const, stmt->limitCount)->isnull)
appendStringInfoString(str, "ALL");
else
else if (stmt->limitOption == LIMIT_OPTION_WITH_TIES)
deparseCExpr(str, stmt->limitCount);

else
deparseExpr(str, stmt->limitCount);

appendStringInfoChar(str, ' ');

if (stmt->limitOption == LIMIT_OPTION_WITH_TIES)
Expand Down Expand Up @@ -4899,13 +4901,15 @@ static void deparseCreateFunctionStmt(StringInfo str, CreateFunctionStmt *create
/* RETURN or BEGIN ... END
*/
if (IsA(create_function_stmt->sql_body, ReturnStmt))
{
deparseReturnStmt(str, castNode(ReturnStmt, create_function_stmt->sql_body));
}
else
{
appendStringInfoString(str, "BEGIN ATOMIC ");
if (linitial(create_function_stmt->sql_body) != NULL)
if (IsA(create_function_stmt->sql_body, List), linitial((List *) create_function_stmt->sql_body) != NULL)
{
List *body_stmt_list = castNode(List, linitial(create_function_stmt->sql_body));
List *body_stmt_list = castNode(List, linitial((List *) create_function_stmt->sql_body));
foreach(lc, body_stmt_list)
{
if (IsA(lfirst(lc), ReturnStmt))
Expand Down
1 change: 1 addition & 0 deletions test/deparse_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ const char* tests[] = {
"CREATE PROCEDURE do_nothing() LANGUAGE sql BEGIN ATOMIC END",
"CREATE PROCEDURE returns_one() LANGUAGE sql BEGIN ATOMIC RETURN 1; END",
"CREATE PROCEDURE updates_and_returns_one() LANGUAGE sql BEGIN ATOMIC UPDATE tbl SET a = 1; RETURN 1; END",
"SELECT 1 FROM tbl LIMIT COALESCE($1, $2)",
};

size_t testsLength = __LINE__ - 4;

0 comments on commit 9430c43

Please sign in to comment.