Skip to content

Commit

Permalink
Create try_convert extension
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Oct 24, 2024
1 parent 1d41230 commit 0c941b3
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions GNUmakefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ifeq ($(with_openssl), yes)
$(MAKE) -C contrib/sslinfo all
endif
$(MAKE) -C contrib/tablefunc all
$(MAKE) -C contrib/try_convert all
ifneq ($(with_uuid),no)
$(MAKE) -C contrib/uuid-ossp all
endif
Expand Down Expand Up @@ -96,6 +97,7 @@ ifeq ($(with_openssl), yes)
$(MAKE) -C contrib/sslinfo $@
endif
$(MAKE) -C contrib/tablefunc $@
$(MAKE) -C contrib/try_convert $@
ifneq ($(with_uuid),no)
$(MAKE) -C contrib/uuid-ossp $@
endif
Expand Down
1 change: 1 addition & 0 deletions contrib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ SUBDIRS = \
test_decoding \
test_parser \
test_shm_mq \
try_convert \
tsearch2 \
tablefunc \
unaccent
Expand Down
19 changes: 19 additions & 0 deletions contrib/try_convert/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# contrib/try_convert/Makefile

MODULE_big = try_convert
OBJS = try_convert.o $(WIN32RES)

EXTENSION = try_convert
DATA = try_convert--1.0.sql
PGFILEDESC = "try_convert - function for type cast"

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/try_convert
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
15 changes: 15 additions & 0 deletions contrib/try_convert/try_convert--1.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* contrib/try_convert/try_convert--1.0.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION try_convert" to load this file. \quit

/* ***********************************************
* try_convert function for PostgreSQL
* *********************************************** */

/* generic file access functions */

CREATE FUNCTION try_convert(anyelement, regtype)
RETURNS int4
AS 'MODULE_PATHNAME', 'try_convert'
LANGUAGE C STRICT;
24 changes: 24 additions & 0 deletions contrib/try_convert/try_convert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "postgres.h"

#include <sys/file.h>
#include <sys/stat.h>
#include <unistd.h>

#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "postmaster/syslogger.h"
#include "storage/fd.h"
#include "utils/builtins.h"
#include "utils/datetime.h"


PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(try_convert);

Datum
try_convert(PG_FUNCTION_ARGS)
{
PG_RETURN_INT32(1);
}
5 changes: 5 additions & 0 deletions contrib/try_convert/try_convert.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# try_convert extension
comment = 'function for type cast'
default_version = '1.0'
module_pathname = '$libdir/try_convert'
relocatable = true

0 comments on commit 0c941b3

Please sign in to comment.