Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sys.columnproperty ordinal #3314

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contrib/babelfishpg_tsql/sql/sys_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3172,8 +3172,8 @@ BEGIN
(SELECT a.attnum FROM pg_catalog.pg_attribute a
WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default))
WHEN 'ordinal' COLLATE sys.database_default THEN
(SELECT b.count FROM (SELECT attname, row_number() OVER () AS count FROM pg_catalog.pg_attribute a
WHERE a.attrelid = object_id AND attisdropped = false AND attnum > 0 ORDER BY a.attnum) AS b WHERE b.attname = property COLLATE sys.database_default)
(SELECT b.count FROM (SELECT attname, row_number() OVER (ORDER BY a.attnum) AS count FROM pg_catalog.pg_attribute a
WHERE a.attrelid = object_id AND attisdropped = false AND attnum > 0) AS b WHERE b.attname = property COLLATE sys.database_default)
WHEN 'isidentity' COLLATE sys.database_default THEN (SELECT
CASE
WHEN char_length(a.attidentity) > 0 THEN 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11431,6 +11431,54 @@ CREATE OR REPLACE AGGREGATE sys.string_agg(TEXT, TEXT) (
PARALLEL = SAFE
);

CREATE OR REPLACE FUNCTION sys.columnproperty(object_id OID, property NAME, property_name TEXT)
RETURNS INTEGER
LANGUAGE plpgsql
STABLE STRICT
AS $$
DECLARE
extra_bytes CONSTANT INTEGER := 4;
return_value INTEGER;
BEGIN
return_value:=
CASE pg_catalog.LOWER(property_name)
WHEN 'charmaxlen' COLLATE sys.database_default THEN (SELECT
CASE
WHEN a.atttypmod > 0 THEN a.atttypmod - extra_bytes
ELSE NULL
END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default))
WHEN 'allowsnull' COLLATE sys.database_default THEN (SELECT
CASE
WHEN a.attnotnull THEN 0
ELSE 1
END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default))
WHEN 'iscomputed' COLLATE sys.database_default THEN (SELECT
CASE
WHEN a.attgenerated != '' THEN 1
ELSE 0
END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id and (a.attname = property COLLATE sys.database_default))
WHEN 'columnid' COLLATE sys.database_default THEN
(SELECT a.attnum FROM pg_catalog.pg_attribute a
WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default))
WHEN 'ordinal' COLLATE sys.database_default THEN
(SELECT b.count FROM (SELECT attname, row_number() OVER (ORDER BY a.attnum) AS count FROM pg_catalog.pg_attribute a
WHERE a.attrelid = object_id AND attisdropped = false AND attnum > 0) AS b WHERE b.attname = property COLLATE sys.database_default)
WHEN 'isidentity' COLLATE sys.database_default THEN (SELECT
CASE
WHEN char_length(a.attidentity) > 0 THEN 1
ELSE 0
END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id and (a.attname = property COLLATE sys.database_default))
ELSE
NULL
END;
RETURN return_value::INTEGER;
EXCEPTION
WHEN others THEN
RETURN NULL;
END;
$$;
GRANT EXECUTE ON FUNCTION sys.columnproperty(object_id OID, property NAME, property_name TEXT) TO PUBLIC;

-- Drops the temporary procedure used by the upgrade script.
-- Please have this be one of the last statements executed in this upgrade script.
DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar);
Expand Down