2000-01-05 12:32:18 -05:00
|
|
|
--
|
|
|
|
|
-- CREATE_FUNCTION_1
|
|
|
|
|
--
|
2002-08-21 20:01:51 -04:00
|
|
|
CREATE FUNCTION widget_in(cstring)
|
1997-04-26 22:58:38 -04:00
|
|
|
RETURNS widget
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/regress@DLSUFFIX@'
|
2014-11-05 11:44:06 -05:00
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
2003-07-27 20:09:16 -04:00
|
|
|
NOTICE: type "widget" is not yet defined
|
2003-07-18 19:20:33 -04:00
|
|
|
DETAIL: Creating a shell type definition.
|
2002-08-21 20:01:51 -04:00
|
|
|
CREATE FUNCTION widget_out(widget)
|
|
|
|
|
RETURNS cstring
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/regress@DLSUFFIX@'
|
2014-11-05 11:44:06 -05:00
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
2003-07-18 19:20:33 -04:00
|
|
|
NOTICE: argument type widget is only a shell
|
2002-08-21 20:01:51 -04:00
|
|
|
CREATE FUNCTION int44in(cstring)
|
|
|
|
|
RETURNS city_budget
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/regress@DLSUFFIX@'
|
2014-11-05 11:44:06 -05:00
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
2003-07-27 20:09:16 -04:00
|
|
|
NOTICE: type "city_budget" is not yet defined
|
2003-07-18 19:20:33 -04:00
|
|
|
DETAIL: Creating a shell type definition.
|
2002-08-21 20:01:51 -04:00
|
|
|
CREATE FUNCTION int44out(city_budget)
|
|
|
|
|
RETURNS cstring
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/regress@DLSUFFIX@'
|
2014-11-05 11:44:06 -05:00
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
2003-07-18 19:20:33 -04:00
|
|
|
NOTICE: argument type city_budget is only a shell
|
2000-01-05 12:32:18 -05:00
|
|
|
CREATE FUNCTION check_primary_key ()
|
2002-08-21 20:01:51 -04:00
|
|
|
RETURNS trigger
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/refint@DLSUFFIX@'
|
2006-02-27 11:09:50 -05:00
|
|
|
LANGUAGE C;
|
2000-01-05 12:32:18 -05:00
|
|
|
CREATE FUNCTION check_foreign_key ()
|
2002-08-21 20:01:51 -04:00
|
|
|
RETURNS trigger
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/refint@DLSUFFIX@'
|
2006-02-27 11:09:50 -05:00
|
|
|
LANGUAGE C;
|
2000-01-05 12:32:18 -05:00
|
|
|
CREATE FUNCTION autoinc ()
|
2002-08-21 20:01:51 -04:00
|
|
|
RETURNS trigger
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/autoinc@DLSUFFIX@'
|
2006-02-27 11:09:50 -05:00
|
|
|
LANGUAGE C;
|
2000-01-05 12:32:18 -05:00
|
|
|
CREATE FUNCTION funny_dup17 ()
|
2002-08-21 20:01:51 -04:00
|
|
|
RETURNS trigger
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/regress@DLSUFFIX@'
|
2006-02-27 11:09:50 -05:00
|
|
|
LANGUAGE C;
|
2000-01-05 12:32:18 -05:00
|
|
|
CREATE FUNCTION ttdummy ()
|
2002-08-21 20:01:51 -04:00
|
|
|
RETURNS trigger
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/regress@DLSUFFIX@'
|
2006-02-27 11:09:50 -05:00
|
|
|
LANGUAGE C;
|
2000-01-05 12:32:18 -05:00
|
|
|
CREATE FUNCTION set_ttdummy (int4)
|
1997-09-24 04:36:47 -04:00
|
|
|
RETURNS int4
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/regress@DLSUFFIX@'
|
2006-02-27 11:09:50 -05:00
|
|
|
LANGUAGE C STRICT;
|
2013-07-02 13:35:14 -04:00
|
|
|
CREATE FUNCTION make_tuple_indirect (record)
|
|
|
|
|
RETURNS record
|
|
|
|
|
AS '@libdir@/regress@DLSUFFIX@'
|
|
|
|
|
LANGUAGE C STRICT;
|
Add a basic atomic ops API abstracting away platform/architecture details.
Several upcoming performance/scalability improvements require atomic
operations. This new API avoids the need to splatter compiler and
architecture dependent code over all the locations employing atomic
ops.
For several of the potential usages it'd be problematic to maintain
both, a atomics using implementation and one using spinlocks or
similar. In all likelihood one of the implementations would not get
tested regularly under concurrency. To avoid that scenario the new API
provides a automatic fallback of atomic operations to spinlocks. All
properties of atomic operations are maintained. This fallback -
obviously - isn't as fast as just using atomic ops, but it's not bad
either. For one of the future users the atomics ontop spinlocks
implementation was actually slightly faster than the old purely
spinlock using implementation. That's important because it reduces the
fear of regressing older platforms when improving the scalability for
new ones.
The API, loosely modeled after the C11 atomics support, currently
provides 'atomic flags' and 32 bit unsigned integers. If the platform
efficiently supports atomic 64 bit unsigned integers those are also
provided.
To implement atomics support for a platform/architecture/compiler for
a type of atomics 32bit compare and exchange needs to be
implemented. If available and more efficient native support for flags,
32 bit atomic addition, and corresponding 64 bit operations may also
be provided. Additional useful atomic operations are implemented
generically ontop of these.
The implementation for various versions of gcc, msvc and sun studio have
been tested. Additional existing stub implementations for
* Intel icc
* HUPX acc
* IBM xlc
are included but have never been tested. These will likely require
fixes based on buildfarm and user feedback.
As atomic operations also require barriers for some operations the
existing barrier support has been moved into the atomics code.
Author: Andres Freund with contributions from Oskari Saarenmaa
Reviewed-By: Amit Kapila, Robert Haas, Heikki Linnakangas and Álvaro Herrera
Discussion: CA+TgmoYBW+ux5-8Ja=Mcyuy8=VXAnVRHp3Kess6Pn3DMXAPAEA@mail.gmail.com,
20131015123303.GH5300@awork2.anarazel.de,
20131028205522.GI20248@awork2.anarazel.de
2014-09-25 17:49:05 -04:00
|
|
|
CREATE FUNCTION test_atomic_ops()
|
|
|
|
|
RETURNS bool
|
|
|
|
|
AS '@libdir@/regress@DLSUFFIX@'
|
|
|
|
|
LANGUAGE C;
|
2017-09-15 08:07:22 -04:00
|
|
|
-- Tests creating a FDW handler
|
|
|
|
|
CREATE FUNCTION test_fdw_handler()
|
|
|
|
|
RETURNS fdw_handler
|
|
|
|
|
AS '@libdir@/regress@DLSUFFIX@', 'test_fdw_handler'
|
|
|
|
|
LANGUAGE C;
|
2002-05-22 13:21:02 -04:00
|
|
|
-- Things that shouldn't work:
|
2006-02-27 11:09:50 -05:00
|
|
|
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE SQL
|
2002-05-22 13:21:02 -04:00
|
|
|
AS 'SELECT ''not an integer'';';
|
2003-07-18 19:20:33 -04:00
|
|
|
ERROR: return type mismatch in function declared to return integer
|
Change unknown-type literals to type text in SELECT and RETURNING lists.
Previously, we left such literals alone if the query or subquery had
no properties forcing a type decision to be made (such as an ORDER BY or
DISTINCT clause using that output column). This meant that "unknown" could
be an exposed output column type, which has never been a great idea because
it could result in strange failures later on. For example, an outer query
that tried to do any operations on an unknown-type subquery output would
generally fail with some weird error like "failed to find conversion
function from unknown to text" or "could not determine which collation to
use for string comparison". Also, if the case occurred in a CREATE VIEW's
query then the view would have an unknown-type column, causing similar
failures in queries trying to use the view.
To fix, at the tail end of parse analysis of a query, forcibly convert any
remaining "unknown" literals in its SELECT or RETURNING list to type text.
However, provide a switch to suppress that, and use it in the cases of
SELECT inside a set operation or INSERT command. In those cases we already
had type resolution rules that make use of context information from outside
the subquery proper, and we don't want to change that behavior.
Also, change creation of an unknown-type column in a relation from a
warning to a hard error. The error should be unreachable now in CREATE
VIEW or CREATE MATVIEW, but it's still possible to explicitly say "unknown"
in CREATE TABLE or CREATE (composite) TYPE. We want to forbid that because
it's nothing but a foot-gun.
This change creates a pg_upgrade failure case: a matview that contains an
unknown-type column can't be pg_upgraded, because reparsing the matview's
defining query will now decide that the column is of type text, which
doesn't match the cstring-like storage that the old materialized column
would actually have. Add a checking pass to detect that. While at it,
we can detect tables or composite types that would fail, essentially
for free. Those would fail safely anyway later on, but we might as
well fail earlier.
This patch is by me, but it owes something to previous investigations
by Rahila Syed. Also thanks to Ashutosh Bapat and Michael Paquier for
review.
Discussion: https://postgr.es/m/CAH2L28uwwbL9HUM-WR=hromW1Cvamkn7O-g8fPY2m=_7muJ0oA@mail.gmail.com
2017-01-25 09:17:18 -05:00
|
|
|
DETAIL: Actual return type is text.
|
2004-03-13 20:58:41 -05:00
|
|
|
CONTEXT: SQL function "test1"
|
2006-02-27 11:09:50 -05:00
|
|
|
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE SQL
|
2002-05-22 13:21:02 -04:00
|
|
|
AS 'not even SQL';
|
2006-03-14 17:48:25 -05:00
|
|
|
ERROR: syntax error at or near "not"
|
2004-03-21 17:29:11 -05:00
|
|
|
LINE 2: AS 'not even SQL';
|
|
|
|
|
^
|
2006-02-27 11:09:50 -05:00
|
|
|
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE SQL
|
2002-05-22 13:21:02 -04:00
|
|
|
AS 'SELECT 1, 2, 3;';
|
2003-07-18 19:20:33 -04:00
|
|
|
ERROR: return type mismatch in function declared to return integer
|
2008-10-31 15:37:56 -04:00
|
|
|
DETAIL: Final statement must return exactly one column.
|
2004-03-13 20:58:41 -05:00
|
|
|
CONTEXT: SQL function "test1"
|
2006-02-27 11:09:50 -05:00
|
|
|
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE SQL
|
2002-05-22 13:21:02 -04:00
|
|
|
AS 'SELECT $2;';
|
2003-07-18 19:20:33 -04:00
|
|
|
ERROR: there is no parameter $2
|
2008-09-01 16:42:46 -04:00
|
|
|
LINE 2: AS 'SELECT $2;';
|
|
|
|
|
^
|
2006-02-27 11:09:50 -05:00
|
|
|
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE SQL
|
2002-05-22 13:21:02 -04:00
|
|
|
AS 'a', 'b';
|
2003-07-18 19:20:33 -04:00
|
|
|
ERROR: only one AS item needed for language "sql"
|
2006-02-27 11:09:50 -05:00
|
|
|
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE C
|
2002-05-22 13:21:02 -04:00
|
|
|
AS 'nosuchfile';
|
2003-07-18 19:20:33 -04:00
|
|
|
ERROR: could not access file "nosuchfile": No such file or directory
|
2006-02-27 11:09:50 -05:00
|
|
|
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE C
|
2008-10-01 18:38:57 -04:00
|
|
|
AS '@libdir@/regress@DLSUFFIX@', 'nosuchsymbol';
|
|
|
|
|
ERROR: could not find function "nosuchsymbol" in file "@libdir@/regress@DLSUFFIX@"
|
2002-05-22 13:21:02 -04:00
|
|
|
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE internal
|
|
|
|
|
AS 'nosuch';
|
|
|
|
|
ERROR: there is no built-in function named "nosuch"
|